목록프로그래머스 SQL 문제풀이(Oracle)/SQL LV3(Oracle) (10)
Creative Code
SELECT * FROM PLACES WHERE HOST_ID IN (SELECT HOST_ID FROM PLACES GROUP BY HOST_ID HAVING count(*) >=2) ORDER BY ID;
SELECT USER_ID, NICKNAME, CITY||' '||STREET_ADDRESS1||' '||STREET_ADDRESS2 AS "전체주소", substr(TLNO,1,3)||'-'||substr(TLNO,4,4)||'-'||substr(TLNO,8,4) AS "전화번호" FROM USED_GOODS_USER WHERE USER_ID IN (SELECT WRITER_ID FROM USED_GOODS_BOARD GROUP BY WRITER_ID HAVING COUNT(WRITER_ID) >= 3) ORDER BY USER_ID DESC;
SELECT B.ANIMAL_ID, B.NAME FROM ANIMAL_INS A RIGHT OUTER JOIN ANIMAL_OUTS B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE A.ANIMAL_ID IS NULL ORDER BY B.ANIMAL_ID;
SELECT DISTINCT A.CAR_ID FROM CAR_RENTAL_COMPANY_CAR A ,CAR_RENTAL_COMPANY_RENTAL_HISTORY B WHERE A.CAR_ID = B.CAR_ID AND A.CAR_TYPE = '세단' AND to_char(B.START_DATE,'YYYY-MM') LIKE '2022-10' ORDER BY A.CAR_ID DESC;
SELECT B.FOOD_TYPE, B.REST_ID, B.REST_NAME, B.FAVORITES FROM (SELECT FOOD_TYPE, MAX(FAVORITES) AS FAVORITES FROM REST_INFO GROUP BY FOOD_TYPE) A, REST_INFO B WHERE A.FOOD_TYPE = B.FOOD_TYPE AND A.FAVORITES = B.FAVORITES ORDER BY A.FOOD_TYPE DESC;
SELECT F.USER_ID, F.NICKNAME, SUM(B.PRICE) AS TOTAL_SALES FROM USED_GOODS_BOARD B, USED_GOODS_USER F WHERE (B.WRITER_ID = F.USER_ID) AND B.STATUS = 'DONE' GROUP BY F.USER_ID, F.NICKNAME HAVING SUM(B.PRICE) >= 700000 ORDER BY TOTAL_SALES;