MySQL

SELECT

AND

SELECT AGE, GENDER
  FROM table1
  WHERE AGE > 12 AND GENDER = 'W';

OR, IN

SELECT GENDER
  FROM table1
  WHERE GENDER IN ('W', 'M');
-- WHERE GENDER = 'W' OR GENDER = 'M';

SELECT GENDER
  FROM table1
  WHERE NOT GENDER IN ('W', 'M');
-- WHERE GENDER != 'W' AND GENDER != 'M';

최댓값, 최솟값

SELECT MAX(age), MIN(age)
  FROM table1;

NULL인 값은 다른 값으로 채우기

SELECT COALESCE(FREEZER_YN, 'N'), IFNULL(FREEZER_YN, 'N')
  FROM table1;

날짜

SELECT DATE_FORMAT(HIRE_YMD, '%Y-%m-%d')
  FROM table1;

SELECT HIRE_YMD
  FROM table1
  WHERE YEAR(HIRE_YMD) = 2022;

COUNT

SELECT COUNT(*) AS NO_AGE
  FROM table1
  WHERE AGE IS NULL;

출력 개수

SELECT AGE, GENDER
  FROM table1
  LIMIT 1;

날짜와 IF

SELECT IF(DATEDIFF(END_DATE, START_DATE)+1>=30, '장기 대여', '단기 대여') AS RENT_TYPE
  FROM COMPANY



Written by@ryuna
개발하면서 배우고 느낀 점을 기록합니다.

GitHub