728x90
조건에 맞는 아이템들의 가격의 총합 구하기
https://school.programmers.co.kr/learn/courses/30/lessons/273709
SELECT SUM(PRICE) AS TOTAL_PRICE
FROM ITEM_INFO
WHERE RARITY = 'LEGEND'
물고기 종류 별 대어 찾기
https://school.programmers.co.kr/learn/courses/30/lessons/293261
SELECT ID
, t2.FISH_NAME
, LENGTH
FROM FISH_INFO t1
JOIN FISH_NAME_INFO t2
ON t1.FISH_TYPE = t2.FISH_TYPE
WHERE (t1.FISH_TYPE, LENGTH) IN
(SELECT FISH_TYPE, MAX(LENGTH) AS LENGTH
FROM FISH_INFO
GROUP BY FISH_TYPE)
ORDER BY t1.ID
--- 다른 풀이 : HAVING 절 사용
SELECT t1.ID, t2.FISH_NAME, t1.LENGTH
FROM FISH_INFO t1
JOIN FISH_NAME_INFO t2
ON t1.FISH_TYPE = t2.FISH_TYPE
WHERE t1.FISH_TYPE IN
(
SELECT FISH_TYPE
FROM FISH_INFO
GROUP BY FISH_TYPE
HAVING LENGTH = MAX(LENGTH)
) ORDER BY ID
연도별 대장균 크기의 편차 구하기
https://school.programmers.co.kr/learn/courses/30/lessons/299310
728x90
'Data Engineering > SQL' 카테고리의 다른 글
[SQL] SQL 실행순서 (0) | 2024.08.21 |
---|---|
[프로그래머스] SELECT 유형 SQL 문제 풀이 (0) | 2024.06.15 |
[MySQL] ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 에러 해결 (0) | 2023.06.06 |
[MySQL] WHERE vs SELECET vs ORDER BY 실행순서 (Unknown column 에러가 나는 이유) (0) | 2023.04.06 |
프로그래머스 SQL - SELECT 문 (0) | 2023.04.03 |