SELECT ANIMAL_TYPE, COUNT(ANIMAL_ID) AS count FROM ANIMAL_INS GROUP BY ANIMAL_TYPE;
SELECT NAME, COUNT(ANIMAL_ID) AS COUNT FROM ANIMAL_INS WHERE NAME IS NOT NULL
GROUP BY NAME HAVING COUNT>=2 ORDER BY NAME;
HAVING
- GROUP์ ์กฐ๊ฑด
SELECT HOUR(DATETIME) AS HOUR, COUNT(ANIMAL_ID) AS COUNT FROM ANIMAL_OUTS
GROUP BY HOUR HAVING HOUR >=9 AND HOUR <20 ORDER BY HOUR;
SET @hour := -1;
SELECT (@hour := @hour+1) AS HOUR,
(SELECT COUNT(ANIMAL_ID) FROM ANIMAL_OUTS WHERE HOUR(DATETIME) = @hour)
FROM ANIMAL_OUTS WHERE @hour < 23 ORDER BY HOUR;
SET
- ๋ณ์ ๋ฑ์ ์ธํ ํ ์ ์์
- @hour := -1 -> hour์ด๋ผ๋ ๋ณ์๋ฅผ -1๋ก ์ด๊ธฐํ
'๐ Programming > SQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[MYSQL] Data INSERT, UPDATE, DELETE (0) | 2021.02.25 |
---|---|
[MYSQL] ์ฐ์ ์ ์๊ฑฐํธ๊ฐ ๋ด๊ธด ์ฅ๋ฐ๊ตฌ๋ (0) | 2021.02.16 |
[MYSQL] SELECT is null FROM Programmers (0) | 2021.02.06 |
[MYSQL] SELECT sum,max,min FROM Programmers (0) | 2020.12.30 |
[MYSQL] SELECT select FROM Programmers (0) | 2020.12.26 |