서울에 위치한 식당 목록 출력하기
https://school.programmers.co.kr/learn/courses/30/lessons/131118
SELECT I.REST_ID, I.REST_NAME, I.FOOD_TYPE, I.FAVORITES, I.ADDRESS, ROUND(AVG(REVIEW_SCORE),2) AS SCORE
FROM REST_INFO I
RIGHT JOIN REST_REVIEW R ON I.REST_ID=R.REST_ID
GROUP BY REST_ID
HAVING I.ADDRESS LIKE '서울%'
ORDER BY SCORE DESC, FAVORITES DESC
리뷰 없는 식당들도 있어서 REST_INFO 테이블이 아니라 REST_REVIEW 테이블 기준으로 조인해야한다
강원도에 위치한 생산공장 목록 출력하기
https://school.programmers.co.kr/learn/courses/30/lessons/131112
SELECT FACTORY_ID, FACTORY_NAME, ADDRESS
FROM FOOD_FACTORY
WHERE ADDRESS LIKE '강원도 %'
ORDER BY FACTORY_ID
모든 레코드 조회하기
https://school.programmers.co.kr/learn/courses/30/lessons/59034
SELECT *
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
오프라인/온라인 판매 데이터 통합하기
https://school.programmers.co.kr/learn/courses/30/lessons/131537
SELECT DATE_FORMAT(SALES_DATE, '%Y-%m-%d') AS SALES_DATE, PRODUCT_ID, USER_ID, SALES_AMOUNT
FROM ONLINE_SALE
WHERE DATE_FORMAT(SALES_DATE, '%Y%m') = '202203'
UNION ALL
SELECT DATE_FORMAT(SALES_DATE, '%Y-%m-%d') AS SALES_DATE, PRODUCT_ID, NULL AS USER_ID, SALES_AMOUNT
FROM OFFLINE_SALE
WHERE DATE_FORMAT(SALES_DATE, '%Y%m') = '202203'
ORDER BY SALES_DATE, PRODUCT_ID, USER_ID
역순 정렬하기
https://school.programmers.co.kr/learn/courses/30/lessons/59035
SELECT NAME, DATETIME
FROM ANIMAL_INS
ORDER BY ANIMAL_ID DESC
아픈 동물 찾기
https://school.programmers.co.kr/learn/courses/30/lessons/59036
SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE INTAKE_CONDITION = 'Sick'
ORDER BY ANIMAL_ID
어린 동물 찾기
https://school.programmers.co.kr/learn/courses/30/lessons/59037
SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE INTAKE_CONDITION != 'Aged'
ORDER BY ANIMAL_ID
동물의 아이디와 이름
https://school.programmers.co.kr/learn/courses/30/lessons/59403
SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
여러 기준으로 정렬하기
https://school.programmers.co.kr/learn/courses/30/lessons/59404
SELECT ANIMAL_ID, NAME, DATETIME
FROM ANIMAL_INS
ORDER BY NAME ASC, DATETIME DESC
상위 n개 레코드
https://school.programmers.co.kr/learn/courses/30/lessons/59405
SELECT *
FROM (
SELECT NAME
FROM ANIMAL_INS
ORDER BY DATETIME ASC
)
WHERE ROWNUM < 2
조건에 맞는 회원수 구하기
https://school.programmers.co.kr/learn/courses/30/lessons/131535
SELECT count(*) as USERS
FROM USER_INFO
WHERE JOINED >= '2021-01-01' AND JOINED < '2022-01-01' AND AGE BETWEEN 20 AND 29
'Data > SQL' 카테고리의 다른 글
[프로그래머스] Lv1 ~Lv.4 with, exists (0) | 2024.05.05 |
---|---|
MySQL Transpose (0) | 2023.01.25 |
[프로그래머스] String, Date (MySQL) (0) | 2023.01.24 |
[프로그래머스] GROUP BY (MySQL) (0) | 2023.01.22 |
[프로그래머스] JOIN (MySQL) (0) | 2023.01.22 |