• SELECT Customers.cust_id, COUNT (Orders .order_num) AS num
  • SELECT Customers.cust_id, COUNT(Orders.order_num) AS num_ord FROM Customers LEFT OUTER JOIN Orders ON Customers.cust_id = Orders.cust_id
  • SELECT Customers.cust_id, Orders.order_num




    Download 44,55 Kb.
    bet11/12
    Sana24.11.2023
    Hajmi44,55 Kb.
    #105026
    1   ...   4   5   6   7   8   9   10   11   12
    Bog'liq
    JSOON

    SELECT Customers.cust_id, Orders.order_num FROM Orders FULL OUTER JOIN Customers ON Orders.cust_id = Customers.cust_id;
    Access, MariaDB, MySQL, OpenOffice Base va SQLite da full outer join sintaksisi qo'llab-quvvatlanmaydi.
    Xulosa funksiyalari bilan birlashmalardan foydalanish. Oldingi darsda ko'rganingizdek, asosiy statistik ma'lumotlarni olish uchun umumlashtiruvchi funksiyalardan foydalaniladi. Hozirgacha bo'lgan barcha misollarda agregat funksiyalari faqat bitta jadvalga qo'llanilgan, ammo ular birlashmalarda ham ishlatilishi mumkin.
    Bir misolni ko'rib chiqing. Aytaylik, siz barcha mijozlar ro'yxatini va ular bergan buyurtmalar sonini olishni xohlaysiz. Buning uchun quyidagi so'rovda COUNT() funksiyasidan foydalaniladi.


    SELECT Customers.cust_id, COUNT (Orders .order_num) AS num ord FROM Customers INNER JOIN Orders ON Customers.cust_id = Orders.cust id GROUP BY Customers.cust_id;

    Ushbu bayonot INNER JOIN spetsifikatsiyasidan foydalanadi


    Customers va Orders jadvallarini bir-biriga bog'lash. GROUP BY bandi ma’lumotlarni mijoz bo‘yicha guruhlaydi, shuning uchun COUNT(orders.order_num) funksiyasini chaqirish har bir mijoz uchun buyurtmalar sonini hisoblash va natijani num_ord ustuni sifatida qaytarish imkonini beradi.
    Xulosa funksiyalaridan boshqa turdagi birikmalar bilan ham foydalanish mumkin.


    SELECT Customers.cust_id, COUNT(Orders.order_num) AS num_ord FROM Customers LEFT OUTER JOIN Orders ON Customers.cust_id = Orders.cust_id GROUP BY Customers.cust_id;


    Natija:


    Download 44,55 Kb.
    1   ...   4   5   6   7   8   9   10   11   12




    Download 44,55 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    SELECT Customers.cust_id, Orders.order_num

    Download 44,55 Kb.