SELECT country, count(*) FROM Customers group by country;
SELECT age, count(*) FROM Customers group by age limit 2;
SELECT status, count(*) FROM Shippings group by status;
SELECT customer_id, count(*) from Orders group by customer_id;
SELECT * FROM Customers group by country;
SELECT
e.customer_id,
e.first_name,
e.last_name,
sum(o.amount)
FROM
customers e
INNER JOIN
orders o ON e.customer_id = o.customer_id
GROUP BY e.customer_id;
Filmlar
Tomoshabin
Reyting
Reyting jadvalida filmlar nechtadan ovozga ekanligini aniqlash.
select film_id, count(*) from reyting group by film_id order by count(*);
Reyting jadvalida filmlar to’plagan ballar va uni kamayish taribida aniqlash.
select film_id, sum(ball) from reyting group by film_id order by sum(ball) desc ;
Reyting va Filmlar jadvallarini bog’lagan holda filmlar to’plagan ballar va uni kamayish taribida aniqlash. 60 balldan yuqorilarini chiqarish.
select film_nomi, sum(ball) from reyting inner join filmlar on reyting.film_id=filmlar.id group by film_id having sum(ball)>60 order by sum(ball) desc ;
Do'stlaringiz bilan baham: |