본문 바로가기

SQL

[MYSQL] 프로그래머스 SQL 문제풀기

1.

SELECT CONCAT('/home','/grep','/src/',BOARD_ID,'/',FILE_ID,FILE_NAME,FILE_EXT) FILE_PATH
FROM USED_GOODS_FILE
WHERE BOARD_ID = (SELECT BOARD_ID
                FROM USED_GOODS_BOARD
                ORDER BY VIEWS DESC
                LIMIT 1)
ORDER BY FILE_ID DESC;

 

 

2.

SELECT E.DEPT_ID, D.DEPT_NAME_EN, ROUND(AVG(E.SAL),0) AVG_SAL
FROM HR_EMPLOYEES E
LEFT JOIN HR_DEPARTMENT D
USING (DEPT_ID)
GROUP BY 1
ORDER BY AVG_SAL DESC;

 

3.

SELECT CAR_ID, 
        MAX(CASE 
                WHEN '2022-10-16' BETWEEN START_DATE AND END_DATE THEN '대여중'
                ELSE '대여 가능' # 중간에 띄어쓰기 안해서 계속 틀리다고 나왔다..띄어쓰기주의
                END) AVAILABILITY
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
GROUP BY 1
ORDER BY 1 DESC;

 

 

 

4.

SELECT *
FROM PLACES
WHERE HOST_ID IN (SELECT HOST_ID
                 FROM PLACES
                 GROUP BY 1
                 HAVING COUNT(NAME) > 1)
ORDER BY ID

'SQL' 카테고리의 다른 글

[SQLD]노랭이 개정판 2장 1~30번 , NULL 정리  (0) 2024.05.18
[MYSQL] LEFT,MID,RIGHT/ SUBSTR  (0) 2024.03.14
[MYSQL] GOALESCE(), 소수점 처리, DATEDIFF(), TIMESTAMPDIFF()  (0) 2024.02.16
[MYSQL] DATE_FORMAT()  (0) 2024.02.14
[MYSQL] Subquery  (0) 2024.01.06