1-bob. Ma`lumotlar bazasining asosiy tushunchalari


WHERE a.snum = b.snum AND b.amt = (SELECT MAX (amt) FROM Orders с


Download 1.69 Mb.
bet60/80
Sana17.06.2023
Hajmi1.69 Mb.
#1542331
1   ...   56   57   58   59   60   61   62   63   ...   80
Bog'liq
ec613b75a51decaf6d60405d564c5683 MySQL po max

WHERE a.snum = b.snum


AND b.amt = (SELECT MAX (amt)

FROM Orders с


WHERE c.odate = b,odate) UNION

SELECT a.snum, sname, onum, ‘Lowest on’, odate FROM Salespeople a,


Orders b WHERE a.snum b.snum AND b.amt = (SEi FCT MIN (amt) FROM Orders с

WHERE c.odate ; b.odate);


Shu paytgacha UNION kalit so‘zi yordamida birlashtirilgan so‘rov natijalari qanday tartibda matnga chiqarilishi to‘g’risida gapirmadik. Birlashtirilgan natijalarni ORDER BY kalit so‘zi yordamida tartiblashtirish mumkin.


Yoqoridagi misolni tartub raqamlariga nisbatan tartiblashni ko‘rib o‘tamiz.

SELECT a.snum, sname, onum, ‘Highest on’, odate FROM Salespeople a.


Orders by WHERE a.snum = b.snum AND b.amt = (SELECT MAX (amt)

FROM Orders с WHERE c.odate = b.odate) UNION


SELECT a.snum, sname, onum. ‘Lowest on’, odate FROM Salespeople a.

Orders by


WHERE a.snum = b.snu AND b.amt = (SELECT MIN (amt) FROM Orders с WHERE c.odate = b.odate)

ORDER BY 3;


Arifmetik operatorlarning ustuvorligi matematikada bo‘lgani kabi bir xil. Agar kerak bo‘lsa, qavslar yordamida operatorlarni qo‘llash tartibi o‘zgartirilishi mumkin - (a + b) * (x / (y-z)). Va yana bir bor takrorlayman, NULL bilan har qanday operatsiya NULL beradi, masalan: 10 + NULL, NULL * 15/3, 100 / NULL - bularning barchasi NULL ga olib keladi. I.e. shunchaki noma'lum qiymatni aytish aniq natijani berolmaydi. So‘rovni tuzishda buni hisobga oling va agar kerak bo‘lsa, NULL qiymatlarni ISNULL, COALEемент funktsiyalari bilan ishlang:


SELECT


ID,Name,

Salary/100*BonusPercent AS Result1, NULL Salary/100*ISNULL(BonusPercent,0) AS Result2, ISNULL Salary/100*COALESCE(BonusPercent,0) AS



Download 1.69 Mb.

Do'stlaringiz bilan baham:
1   ...   56   57   58   59   60   61   62   63   ...   80




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