PROGRAMMERS/SQL
-
[프로그래머스] [MySQL] [Level 3] [JOIN] 없어진 기록 찾기PROGRAMMERS/SQL 2022. 10. 13. 22:11
-- 코드를 입력하세요 SELECT A.ANIMAL_ID, A.NAME FROM ANIMAL_OUTS A LEFT OUTER JOIN ANIMAL_INS B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE B.ANIMAL_ID is NULL ORDER BY A.ANIMAL_ID SELECT ANIMAL_OUTS.ANIMAL_ID, ANIMAL_OUTS.NAME FROM ANIMAL_OUTS LEFT JOIN ANIMAL_INS ON ANIMAL_INS.ANIMAL_ID = ANIMAL_OUTS.ANIMAL_ID WHERE ANIMAL_INS.ANIMAL_ID IS NULL ORDER BY ANIMAL_INS.ANIMAL_ID;
-
[프로그래머스] [MySQL] [Level 3] [JOIN] 있었는데요 없었습니다PROGRAMMERS/SQL 2022. 10. 13. 22:01
-- 코드를 입력하세요 SELECT ANIMAL_INS.ANIMAL_ID, ANIMAL_INS.NAME FROM ANIMAL_INS LEFT JOIN ANIMAL_OUTS ON ANIMAL_INS.ANIMAL_ID = ANIMAL_OUTS.ANIMAL_ID WHERE ANIMAL_INS.DATETIME > ANIMAL_OUTS.DATETIME ORDER BY ANIMAL_INS.DATETIME SELECT A.ANIMAL_ID, A.NAME FROM ANIMAL_INS AS A, ANIMAL_OUTS AS B WHERE A.ANIMAL_ID = B.ANIMAL_ID AND A.DATETIME > B.DATETIME ORDER BY A.DATETIME;
-
[프로그래머스] [MySQL] [Level 3] [String, Date] 오랜 기간 보호한 동물(2)PROGRAMMERS/SQL 2022. 10. 13. 21:54
SELECT A.ANIMAL_ID, A.NAME FROM ANIMAL_INS AS A, ANIMAL_OUTS AS B WHERE A.ANIMAL_ID = B.ANIMAL_ID ORDER BY B.DATETIME - A.DATETIME DESC LIMIT 2 SELECT ANIMAL_INS.ANIMAL_ID, ANIMAL_INS.NAME FROM ANIMAL_INS LEFT JOIN ANIMAL_OUTS ON ANIMAL_INS.ANIMAL_ID = ANIMAL_OUTS.ANIMAL_ID ORDER BY DATEDIFF(ANIMAL_OUTS.DATETIME, ANIMAL_INS.DATETIME) DESC LIMIT 2;
-
[프로그래머스] [MySQL] [Level 3] [String, Date] 조건별로 분류하여 주문상태 출력하기PROGRAMMERS/SQL 2022. 10. 13. 17:47
SELECT ORDER_ID, PRODUCT_ID, DATE_FORMAT(OUT_DATE, '%Y-%m-%d') AS OUR_DATE, CASE WHEN OUT_DATE IS NULL THEN '출고미정' WHEN DATEDIFF(OUT_DATE, "2022-05-01") > 0 THEN '출고대기' ELSE '출고완료' END AS '출고여부' FROM FOOD_ORDER ORDER BY ORDER_ID ASC; DATEDIFF DATEDIFF(날짜1, 날짜2); 날짜1 - 날짜2 (날짜가 뒤일수록 큰 수) TIMESTAMPDIFF TIMESTAMPDIFF(단위, 날짜1, 날짜2); 날짜2 - 날짜1 두 날짜 간의 차이를 단위 로 표현 단위 SECOND - 초 MINUTE - 분 HOUR - 시 DAY..