WHERE a.snum = b.snum
AND b.amt = (SELECT MAX (amt)
FROM Orders с
WHERE c.odate = b,odate) UNION
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
Do'stlaringiz bilan baham: |