Sql server® 2012 t-sql fundamentals


   Microsoft SQL Server 2012 T-SQL Fundamentals 7



Download 10,93 Mb.
Pdf ko'rish
bet145/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   141   142   143   144   145   146   147   148   ...   443
Bog'liq
BookSQL

94  

Microsoft SQL Server 2012 T-SQL Fundamentals



7

Using the HR.Employees table, figure out the SELECT statement that returns for each employee the 

gender based on the title of courtesy. For ‘Ms. ‘ and ‘Mrs.’ return ‘Female’; for ‘Mr. ‘ return ‘Male’; and 

in all other cases (for example, ‘Dr. ‘) return ‘Unknown’.



Tables involved: TSQL2012 database and the HR.Employees table



Desired output:



empid       firstname  lastname             titleofcourtesy           gender 

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

1           Sara       Davis                Ms.                       Female  

2           Don        Funk                 Dr.                       Unknown 

3           Judy       Lew                  Ms.                       Female  

4           Yael       Peled                Mrs.                      Female  

5           Sven       Buck                 Mr.                       Male    

6           Paul       Suurs                Mr.                       Male    

7           Russell    King                 Mr.                       Male    

8           Maria      Cameron              Ms.                       Female  

9           Zoya       Dolgopyatova         Ms.                       Female  

 

(9 row(s) affected)



8

Write a query against the Sales.Customers table that returns for each customer the customer ID and 

region. Sort the rows in the output by region, having NULL marks sort last (after non-NULL values). 

Note that the default sort behavior for NULL marks in T-SQL is to sort first (before non-NULL values).



Tables involved: TSQL2012 database and the Sales.Customers table



Desired output (abbreviated):



custid      region 

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

55          AK 

10          BC 

42          BC 

45          CA 

37          Co. Cork 

33          DF 

71          ID 

38          Isle of Wight 

46          Lara 

78          MT 

... 

1           NULL 



2           NULL 

3           NULL 

4           NULL 

5           NULL 

6           NULL 

7           NULL 

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   141   142   143   144   145   146   147   148   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish