Having standart so’zi orqali so`rovlar yaratish
Sintaksisga ega
SELECT ustun_nomi
FROM jadval_nomi
WHERE shart
GROUP BY ustun_nomi
HAVING shart
ORDER BY ustun_nomi;
SQL HAVING misollar
Bizda talaba5 deb nomlangan quyidagi jadval bo’lsin.
Quyidagi SQL bayonotida har bir tumandagi talabalar soni ko'rsatilgan. Faqat 5 dan ortiq mijozlari bo'lgan talabalar kiradi:
Misol
SELECT COUNT(id), manzili
FROM talaba5
GROUP BY manzili
HAVING COUNT(id) > 1;
Quyidagi SQL bayonotida har bir tumandagi talabalar soni yuqoridan pastgacha tartiblangan (Faqat 1 dan ortiq mijozlari bo'lgan mamlakatlar kiradi):
Misol
SELECT COUNT(id), manzili
FROM talaba5
GROUP BY manzili
HAVING COUNT(id) > 1
order by count(id) desc
/////////////////////
SELECT COUNT(id), manzili
FROM talaba5
GROUP BY manzili
HAVING COUNT(id) >= 2
order by count(id) desc
Do'stlaringiz bilan baham: |