728x90
๊ณ ์์ด์ ๊ฐ๋ ๋ช ๋ง๋ฆฌ ์์๊น
์ ๋ต
SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE)
FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE
ORDER BY NAME DESC
๊ด๋ จ ๋ด์ฉ
SELECT ์ปฌ๋ผ
FROM ํ
์ด๋ธ
GROUP BY ๊ทธ๋ฃนํํ ์ปฌ๋ผ
ํน์ ์ปฌ๋ฆผ์ ๊ธฐ์ค์ผ๋ก ๊ทธ๋ฃนํ!
๋๋ช ๋๋ฌผ ์ ์ฐพ๊ธฐ
์ ๋ต
SELECT NAME, COUNT(NAME)
FROM ANIMAL_INS
WHERE NAME is not null
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME
๊ด๋ จ ๋ด์ฉ
SELECT ์ปฌ๋ผ
FROM ํ
์ด๋ธ
WHERE ์กฐ๊ฑด์
GROUP BY ๊ทธ๋ฃนํํ ์ปฌ๋ผ
HAVING ์กฐ๊ฑด์
WHERE : ๊ทธ๋ฃนํ ํ๊ธฐ ์ ์ ์กฐ๊ฑด
HAVING : ๊ทธ๋ฃนํํ ํ์ ์กฐ๊ฑด
์ ์ ์๊ฐ ๊ตฌํ๊ธฐ(1)
์ ๋ต
SELECT HOUR(DATETIME) HOUR, COUNT(DATETIME)
FROM ANIMAL_OUTS
GROUP BY HOUR(DATETIME)
HAVING HOUR > 8 and HOUR < 20
ORDER BY HOUR
๊ด๋ จ ๋ด์ฉ
SKIP
์ ์ ์๊ฐ ๊ตฌํ๊ธฐ(2)
์ ๋ต
SET @hour := -1;
SELECT (@hour := @hour + 1) HOUR,
(SELECT COUNT(@hour) FROM ANIMAL_OUTS WHERE @hour = HOUR(DATETIME))
FROM ANIMAL_OUTS
HAVING @hour > -1 and @hour < 24
ORDER BY HOUR
๊ด๋ จ ๋ด์ฉ
https://techblog-history-younghunjo1.tistory.com/146
728x90