Sql server® 2012 t-sql fundamentals


   Microsoft SQL Server 2012 T-SQL Fundamentals 5-1



Download 10,93 Mb.
Pdf ko'rish
bet237/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   233   234   235   236   237   238   239   240   ...   443
Bog'liq
BookSQL

186  

Microsoft SQL Server 2012 T-SQL Fundamentals



5-1

Create an inline function that accepts as inputs a supplier ID (@supid AS INT) and a requested num-

ber of products (@n AS INT). The function should return @n products with the highest unit prices that 

are supplied by the specified supplier ID.



Tables involved: Production.Products



When issuing the following query:



SELECT * FROM Production.TopProducts(5, 2);



Desired output:

productid   productname        unitprice 

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

12          Product OSFNS      38.00 

11          Product QMVUN      21.00 

 

(2 row(s) affected)



5-2

Using the CROSS APPLY operator and the function you created in Exercise 4-1, return, for each sup-

plier, the two most expensive products.



Desired output (shown here in abbreviated form).

supplierid  companyname       productid   productname     unitprice 

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

8           Supplier BWGYE    20          Product QHFFP   81.00 

8           Supplier BWGYE    68          Product TBTBL   12.50 

20          Supplier CIYNM    43          Product ZZZHR   46.00 

20          Supplier CIYNM    44          Product VJIEO   19.45 

23          Supplier ELCRN    49          Product FPYPN   20.00 

23          Supplier ELCRN    76          Product JYGFE   18.00 

5           Supplier EQPNC    12          Product OSFNS   38.00 

5           Supplier EQPNC    11          Product QMVUN   21.00 

... 


 

(55 row(s) affected)



When you’re done, run the following code for cleanup.



IF OBJECT_ID('Sales.VEmpOrders') IS NOT NULL 

  DROP VIEW Sales.VEmpOrders; 

IF OBJECT_ID('Production.TopProducts') IS NOT NULL 

  DROP FUNCTION Production.TopProducts;

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   233   234   235   236   237   238   239   240   ...   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