• 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 WHERE City = San Jose);
  • Korrellangan (mutanosib) joylashtirilgan ostki so‘rovlar.
  • SELECT * FROM Customers a WHERE ‘1990/10/03’ IN
  • SELECT * FROM Orders WHERE AMT >




    Download 1,38 Mb.
    Pdf ko'rish
    bet44/79
    Sana30.01.2024
    Hajmi1,38 Mb.
    #148346
    1   ...   40   41   42   43   44   45   46   47   ...   79
    Bog'liq
    Mundarija kirish

    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. 


    65 
    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 oktyabrda buyurtma bergan xamma buyurtmachilarni 
    toping. 
    SELECT * FROM Customers a WHERE ‘1990/10/03’ IN 

    Download 1,38 Mb.
    1   ...   40   41   42   43   44   45   46   47   ...   79




    Download 1,38 Mb.
    Pdf ko'rish