SELECT ANIMAL_ID, NAME FROM ANIMAL_INS;
SELECT ANIMAL_ID, NAME AS '이름' FROM ANIMAL_INS;
SELECT userID, Name FROM usertbl WHERE birthYear >= 1970 AND height >= 182;
SELECT userID, Name FROM usertbl WHERE birthYear >= 1970 OR height >= 182;
SELECT name, height FROM usertbl WHERE height BETWEEN 180 AND 183;
SELECT name, addr FROM usertbl WHERE addr IN ('경남','전남','경북');
SELECT name, height FROM usertbl WHERE name LIKE '김%';
SELECT ANIMAL_ID, NAME, DATETIME FROM ANIMAL_INS ORDER BY NAME, DATETIME DESC;
SELECT NAME FROM ANIMAL_INS ORDER BY DATETIME LIMIT 1;
SELECT MAX(DATETIME) AS '시간' FROM ANIMAL_INS;
SELECT MIN(DATETIME) AS '시간' FROM ANIMAL_INS;
SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE) AS 'count' FROM ANIMAL_INS GROUP BY ANIMAL_TYPE ORDER BY ANIMAL_TYPE;
SELECT NAME, COUNT(NAME) AS 'COUNT' FROM ANIMAL_INS GROUP BY NAME HAVING COUNT >= 2 ORDER BY NAME;
SELECT TRUNCATE(PRICE, -4) AS PRICE_GROUP, COUNT(*) AS PRODUCTS
FROM PRODUCT GROUP BY PRICE_GROUP ORDER BY PRICE_GROUP;
https://school.programmers.co.kr/learn/courses/30/lessons/133026
SELECT INGREDIENT_TYPE, SUM(TOTAL_ORDER) AS TOTAL_ORDER
FROM FIRST_HALF LEFT JOIN ICECREAM_INFO ON FIRST_HALF.FLAVOR = ICECREAM_INFO.FLAVOR
GROUP BY INGREDIENT_TYPE;
SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL;
SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NOT NULL;
SELECT DATE_FORMAT('20200405','%Y/%m/%d')
-> 2020/04/05
SELECT DATE_FORMAT('20200405','%Y-%m-%d')
-> 2020-04-05
SELECT DATE_FORMAT('2020-04-05', '%W %M %Y');
-> Sunday April 2020
SELECT
HISTORY_ID,
CAR_ID,
DATE_FORMAT(START_DATE, '%Y-%m-%d') AS START_DATE,
DATE_FORMAT(END_DATE, '%Y-%m-%d') AS END_DATE,
CASE
WHEN DATEDIFF(END_DATE, START_DATE) + 1 >= 30 THEN "장기 대여"
ELSE "단기 대여"
END AS RENT_TYPE
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE START_DATE BETWEEN '2022-09-01' AND '2022-09-30'
ORDER BY HISTORY_ID DESC;
https://school.programmers.co.kr/learn/challenges?tab=sql_practice_kit
https://paris-in-the-rain.tistory.com/100