• SELECT CITY, SUM(QUOTA), SUM(SALESREPS.SALES) FROM OFFICES, SALESREPS WHERE OFFICE = REP_OFFICE GROUP BY CITY HAVING COUNT(*) >= 2
  • SELECT REP, AVG(AMOUNT) FROM ORDERS GROUP BY REP HAVING SUM(AMOUNT) > 300




    Download 84,3 Kb.
    bet13/18
    Sana12.01.2024
    Hajmi84,3 Kb.
    #135637
    1   ...   10   11   12   13   14   15   16   17   18
    Bog'liq
    Mavzu Microsoft Access dasturida hisobotlar yaratish. Reja-fayllar.org

    SELECT REP, AVG(AMOUNT)
    FROM ORDERS
    GROUP BY REP
    HAVING SUM(AMOUNT) > 300
    Ko‗rinib turibdiki HAVING SUM(AMOUNT) > 300 ifodasi satrlarni guruhlash
    sharti sifatida kelmoqda.
    Agar SUM(AMOUNT) > 300 sharti yolg‗on bo‗lsa, bu guruh natijaviy to‗plamdan
    chiqariladi. Agar rost bo‗lsa guruh natijaviy to‗plamga kiradi!
    Yana bir misol ko‗raylik: Ikki va undan ortiq xizmatchiga ega har bir ofisning
    hamma xizmatchilari uchun rejadagi va haqiqiy sotuvlar umumiy hajmini
    hisoblash.
    SELECT CITY, SUM(QUOTA), SUM(SALESREPS.SALES)
    FROM OFFICES, SALESREPS
    WHERE OFFICE = REP_OFFICE
    GROUP BY CITY
    HAVING COUNT(*) >= 2

    Bu misolda WHERE va HAVING ifodalari o‗z funksiyalarini bajaradilar. Shunga
    e‘tibor berish kerakki HAVING ifodasida agregat funksiyalardan foydalaniladi,
    So‗rov bajarilishini ko‗ramiz:
    OFFICES va SALESREPS jadvallari xizmatchi yashaydigan shaharni topish uchun
    qo‗shiladilar.
    Qo‗shilgan jadval satrlarlari ofislar bo‗yicha guruhlanadilar. Ikkidan kam
    satrga ega guruhlar tashlab yuboriladi. Ular HAVING ifodasi talabiga javob
    bermaydilar.
    Har bir guruh uchun haqiqiy va rejadagi sotuvlar hajmlari hisoblanadi.
    Murakkabroq misolni ko‗ramiz: Har bir tovar nomi uchun narxi, ombordagi
    soni va buyurtma berilganlar umumiy sonini ko‗rsating, agar uning uchun
    buyurtma berilganlar umumiy soni ombordagi umumiy soni 75 foizidan ko‗p
    bo‗lsa.
    SELECT DESCRIPTION, PRICE, QTY_ON_HAND, SUM(QTY)
    FROM PRODUCTS, ORDERS
    WHERE MFR = MFR_ID
    GROUP BY MFR_ID, PRODUCT_ID, DESCRIPTION, PRICE, QTY_ON_HAND
    HAVING SUM(QTY) > (0.75 * QTY_ON_HAND)
    ORDER BY QTY_ON_HAND DESC
    HAVING uchung qo‗shimcha chegaralar mavjuddir. Bu ifoda juda bo‗lmasa bitta
    agregat funksiyani o‗z ichiga olishi kerak. Chunki WHERE alohida satrlarga
    HAVING satrlar guruhlariga qo‗llanadi. NULL qiymat uchun WHERE ifodasiga
    o‗xshab quyidagi qoida o‗rinli Agar izlash sharti NULL qiymatga ega bo‗lsa satrlar
    guruhi tashlab yuboriladi. HAVING ifodasini GROUP BY siz qo‗llash mumkin.
    Bu holda natija hamma satrlardan iborat guruh deb qaraladi, lekin amalda bu kam
    qo‗llanadi.

    Download 84,3 Kb.
    1   ...   10   11   12   13   14   15   16   17   18




    Download 84,3 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    SELECT REP, AVG(AMOUNT) FROM ORDERS GROUP BY REP HAVING SUM(AMOUNT) > 300

    Download 84,3 Kb.