Group by va order by standart so‘zlaridan foydalanib so’rov yaratish. Order by


Download 41.63 Kb.
Sana06.11.2021
Hajmi41.63 Kb.
#171296

GROUP BY va ORDER BY

standart so‘zlaridan foydalanib so’rov yaratish.

ORDER BY operatori qiymatlarni bir yoki bir nechta ustunlar bo'yicha saralaydi. ORDER BY operatori sintaksisi quyidagicha:

SELECT


select_list

FROM


table_name

ORDER BY

column1 [ASC|DESC],

column2 [ASC|DESC],

...;

ASC kalit so’zi ustunni o’sish tartibida saralashni, DESC esa kamayish tartibida saralashni bildiradi. Odatiy qiymat ASC.



Natijaviy to’plamni column1 ustuni bo’yicha o’sish tartibida saralash:

ORDER BY column1 ASC;

Yoki

ORDER BY column1;



Natijaviy to’plamni column1 ustuni bo’yicha o’sish tartibida saralash:

ORDER BY column1 DESC;



ORDER BY operatori SELECT va FROM operatorlaridan so’ng bajariladi:

Familiya ustuni bo’yicha saralash:

SELECT

contactLastname,



contactFirstname

FROM


customers

ORDER BY


contactLastname;

Familiya ustuni bo’yicha kamayish tartibida saralash:

SELECT

contactLastname,



contactFirstname

FROM


customers

ORDER BY


contactLastname DESC;

Saralashni ifoda orqali amalga oshirish:

SELECT

orderNumber,

orderlinenumber,

quantityOrdered * priceEach

FROM

orderdetails



ORDER BY

quantityOrdered * priceEach DESC;



GROUP BY operatori qatorlar to'plamini ustunlar yoki ifodalar qiymatlari bo'yicha natijaviy qatorlar to'plamiga guruhlaydi. GROUP BY operatori har bir guruh uchun bitta qatorni qaytaradi. Boshqacha qilib aytganda, natijalar to'plamidagi qatorlar sonini kamaytiradi.

GROUP BY operatori ko’pincha agregat funksiyalar bilan ishlatiladi. GROUP BY operatori sintaksisi quyidagicha:

SELECT

c1, c2,..., cn, aggregate_function(ci)

FROM

table


WHERE

where_conditions

GROUP BY c1 , c2,...,cn;

GROUP BY operatori bajarilish o’rni:



GROUP BY operatori bilan agregat funksiyalarning ishlatishiga misol:




Download 41.63 Kb.

Do'stlaringiz bilan baham:




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