[프로그래머스 SQL 고득점 Kit] String, Date: 카테고리 별 상품 개수 구하기
문제 정답 SELECT SUBSTRING(PRODUCT_CODE, 1, 2) AS CATEGORY, COUNT(*) AS PRODUCTS FROM PRODUCT GROUP BY CATEGORY ORDER BY CATEGORY
문제 정답 SELECT SUBSTRING(PRODUCT_CODE, 1, 2) AS CATEGORY, COUNT(*) AS PRODUCTS FROM PRODUCT GROUP BY CATEGORY ORDER BY CATEGORY
문제 정답 SELECT USER_ID, NICKNAME, CONCAT_WS(' ', CITY, STREET_ADDRESS1, STREET_ADDRESS2) AS 전체주소, CONCAT_WS('-', SUBSTRING(TLNO, 1, 3), SUBSTRING(TLNO, 4, 4), SUBSTRING(TLNO, 8, 4)) AS 전화번호 FROM USED_GOODS_BOARD AS A JOIN USED_GOODS_USER AS B ON A.WRITER_ID = B.USER_ID GROUP BY WRITER_ID HAVING COUNT(WRITER_ID) >= 3 ORDER BY USER_ID DESC
문제 정답 SELECT * FROM CAR_RENTAL_COMPANY_CAR WHERE OPTIONS LIKE '%네비게이션%' ORDER BY CAR_ID DESC
문제 정답 SELECT HISTORY_ID, CAR_ID, DATE_FORMAT(START_DATE, '%Y-%m-%d'), DATE_FORMAT(END_DATE, '%Y-%m-%d'), CASE WHEN DATEDIFF(END_DATE, START_DATE) + 1 >= 30 THEN '장기 대여' ELSE '단기 대여' END RENT_TYPE FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE START_DATE LIKE '2022-09%' ORDER BY HISTORY_ID DESC
문제 정답 SELECT CAR_ID, ROUND(AVG(DATEDIFF(END_DATE, START_DATE) + 1), 1) AS AVERAGE_DURATION FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY GROUP BY CAR_ID HAVING AVG(DATEDIFF(END_DATE, START_DATE) + 1) >= 7 ORDER BY AVERAGE_DURATION DESC, CAR_ID DESC
문제 정답 SELECT BOARD_ID, WRITER_ID, TITLE, PRICE, CASE WHEN STATUS = 'SALE' THEN '판매중' WHEN STATUS = 'RESERVED' THEN '예약중' WHEN STATUS = 'DONE' THEN '거래완료' END STATUS FROM USED_GOODS_BOARD WHERE CREATED_DATE LIKE '2022-10-05' ORDER BY BOARD_ID DESC
문제 정답 SELECT COUNT(*) AS USERS FROM USER_INFO WHERE AGE IS NULL
문제 정답 SELECT ANIMAL_TYPE, IFNULL(NAME, 'No name') AS NAME, SEX_UPON_INTAKE FROM ANIMAL_INS ORDER BY ANIMAL_ID
문제 정답 SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NOT NULL ORDER BY ANIMAL_ID
문제 정답 SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL ORDER BY ANIMAL_ID