• SELECT * FROM Orders WHERE AMT > ( SELECT AVG (AMT) FROM Orders WHERE ODate = ‘1990/10/04’ );
  • SELECT * FROM Orders WHERE SNum IN ( SELECT SNum FROM Salepeople WHERE City = London );
  • SELECT Rating, COUNT (DISTINCT CNum) FROM Customers GROUP BY Rating HAVING Rating > ( SELECT AVG (Rating) FROM Customers
  • Murakkab so`rovlar yaratish. Jadvallarni jamlashtirish




    Download 34,52 Kb.
    bet4/10
    Sana11.12.2023
    Hajmi34,52 Kb.
    #116098
    1   2   3   4   5   6   7   8   9   10
    Bog'liq
    Baza

    SELECT * FROM Orders
    WHERE SNum = ( SELECT DISTINCT SNum FROM Orders
    WHERE CNum = 21 );
    Bu xolda ostki so‘rov faqat bitta 11 qiymat chiqaradi, lekin umumiy xolda bir necha qiymatlar bo‘lishi mumkin va ular ichidan DISTINCT faqat bittasini tanlaydi.
    Ixtiyoriy sondagi satrlar uchun avtomatik ravishda bitta qiymat xosil qiluvchi funksiya turi - agregat funksiya bo‘lib, undan ostki so‘rovda foydalanish mumkin.
    Masalan, siz summasi 4 oktyabrdagi bajarilishi lozim bo‘lgan buyurtmalar summasi o‘rta qiymatidan yuqori bo‘lgan xamma buyurtmalarni ko‘rmoqchisiz:
    SELECT * FROM Orders
    WHERE AMT >
    ( SELECT AVG (AMT) FROM Orders
    WHERE ODate = ‘1990/10/04’ );
    SHuni nazarda tutish kerakki guruxlangan agregat funksiyalar GROUP BY ifodasi terminlarida aniqlangan agregat funksiyalar bo‘lsa ko‘p qiymatlar xosil qilishi mumkin.
    Agar ostki so‘rov IN operatoridan foydalanilsa, ixtiyoriy sondagi satrlar xosil qilish mumkin.
    Misol: Londondagi sotuvchilar uchun xamma buyurtmalarni ko‘rsatish.
    SELECT * FROM Orders
    WHERE SNum IN
    ( SELECT SNum FROM Salepeople
    WHERE City = 'London' );
    Bu natijani jamlanma orqali xosil qilish mumkin. Lekin odatda ostki sщrovli sщrovlar tezroы bajariladi. Siz ostki so‘rov SELECT jumlasida ustunga asoslangan ifodadan foydalanishingiz mumkin. Bu relyasion operatorlar yordamida yoki IN yordamida amalga oshirilishi mumkin. Siz ostki so‘rovlarni HAVING ichida ishlatishingiz mumkin. Bu ostki so‘rovlar agar ko‘p qiymatlar qaytarmasa xususiy agregat funksiyalaridan yoki GROUP BY yoki HAVING operatorlaridan foydalanishi mumkin.
    Misol:
    SELECT Rating, COUNT (DISTINCT CNum) FROM Customers
    GROUP BY Rating
    HAVING Rating >
    ( SELECT AVG (Rating) FROM Customers
    WHERE City = 'San Jose' );
    Bu komanda San Jose dagi baxolari o‘rtachadan yuqori bo‘lgan buyurtmachilarni aniqlaydi.
    Korrellangan (mutanosib) joylashtirilgan ostki so‘rovlar.
    SQL tilida ostki so‘rovlardan foydalanilganda tashqi so‘rov FROM qismidagi ichki so‘rovga mutanosib so‘rov yordamida murojaat qilishingiz mumkin. Bu xolda ostki so‘rov asosiy so‘rov xar bir satri uchun bir martadan bajariladi.
    Misol: 3-e oktyabrda buyurtma bergan xamma buyurtmachilarni toping.

    Download 34,52 Kb.
    1   2   3   4   5   6   7   8   9   10




    Download 34,52 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Murakkab so`rovlar yaratish. Jadvallarni jamlashtirish

    Download 34,52 Kb.