11-1
SELECT o.id 'order_id',
p.name 'product_name'
FROM orders o
JOIN products p ON o.product_id = p.id
11-2
SELECT p.id 'product_id',
SUM(p.price * o.quantity) 'total'
FROM orders o
JOIN products p ON o.product_id = p.id
GROUP BY p.id
ORDER BY total DESC
LIMIT 1
11-3
SELECT product_id, SUM(quantity) 'total'
FROM orders o
GROUP BY product_id
11-4
SELECT p.name
FROM orders o
JOIN products p ON o.product_id = p.id
WHERE o.order_date > '2023-03-03'
11-5
SELECT p.name,
SUM(o.quantity) '판매수량'
FROM orders o
JOIN products p ON o.product_id = p.id
GROUP BY p.name
ORDER BY SUM(o.quantity) DESC
LIMIT 1
11-6
SELECT o.product_id,
AVG(o.quantity) '평균주문수량'
FROM orders o
GROUP BY o.product_id
11-7
SELECT p.id,
p.name
FROM products p
JOIN orders o ON p.id = o.product_id
WHERE p.id IS NULL
----------------------------------------
달리기반1
SELECT COUNT(1) 'name_cnt'
from users u
where SUBSTR(name,1,1)="김"
--------------------------------------------
달리기반2
SELECT DATE(created_at) 'created_at',
ROUND(AVG(point)) 'average_points'
FROM point_users
GROUP BY 1
'자유학습 기록' 카테고리의 다른 글
로그라이크 과제 트러블 슈팅 (0) | 2024.11.18 |
---|---|
1주차 팀페이지 만들기 프로젝트 KPT회고 (0) | 2024.11.01 |
sql 걷기반 9~11 (0) | 2024.10.24 |
sql 걷기반 6~8번 (0) | 2024.10.24 |
SQL 걷기반 9 (0) | 2024.10.16 |