SQL Server face test for a foreign company

Source: Internet
Author: User
Tags getdate

Question 1:can Your use a batch SQL or store procedure to calculating the number of days in a Month

Answer 1: Find the number of days of the month

Select DatePart Dd,dateadd (Dd,-1,dateadd (Mm,1,cast (getdate () as varchar) + '-' +cast (Month (GETDATE ()) as varchar) + ' -01 ' as DateTime))

Question2:can a SQL statement to calculating it!

How can I print ' to ' for books, ' sell for between $ and $, ' unknown ' for books whose The price is null, and ' other "For all other prices?"

Answer 2:

Select Bookid,bookname,price=case is null then ' unknown '

When price between the ' then ' else price end

From books

Question3:can a SQL statement to finding duplicate values!

How can I find authors and the same last name?

You can use the table authors in datatabase pubs. I want to get the result as below:

Output:

au_lname number_dups

---------------------------------------- -----------

Ringer 2

(1 row (s) affected)

Answer 3

Select Au_lname,number_dups=count (1) from authors GROUP by au_lname

Question4:can you create a cross-tab on my SQL server!

How can I get the "the" "the" the "the" the "the" about sale quality for each store and each quarter and the total sale quality to each quarter at Year 1993?

You can use the table, sales and stores in datatabase pubs.

Table Sales Record all sale detail the item for each store. Column store_id is the ID of each store, ord_date be the order date of each sale item, and column qty is the sale qulity. Table Stores record all store information.

I want to get the result look like as below:

Output:

stor_name                Total    Qtr1    Qtr2    Qtr3    Qtr4    
---------------------------------------- ----------- ----------- ----------- ----------- -----------
Barnum's                 50     0      50     0      0
Bookbeat                 55     25     30     0      0
Doc-U-Mat: Quality Laundry and Books   85     0      85     0      0
Fricative Bookshop            60     35     0      0      25
Total                  250     60     165     0      25

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.