1. ๊ณ ์์ด์ ๊ฐ๋ ๋ช ๋ง๋ฆฌ ์์๊น |
[์ ๋ต ์ ์ด๋์]
SELECT
ANIMAL_TYPE,
COUNT(ANIMAL_TYPE) AS 'count'
FROM
ANIMAL_INS
GROUP BY
ANIMAL_TYPE;
2. ๋๋ช ๋๋ฌผ ์ ์ฐพ๊ธฐ |
[์ ๋ต ์ ์ด๋์]
SELECT
NAME,
COUNT(NAME) AS 'COUNT'
FROM
ANIMAL_INS
WHERE
NAME IS NOT NULL -- ์ด๋ฆ์ด ์๋ ๋๋ฌผ์ ์ง๊ณ์์ ์ ์ธ
GROUP BY
NAME -- ์ด๋ฆ ์
HAVING
COUNT >= 2; -- ๋ ๋ฒ ์ด์ ์ฐ์ธ ์ด๋ฆ
3. ์ ์ ์๊ฐ ๊ตฌํ๊ธฐ(1) |
[์ ๋ต ์ ์ด๋์]
SELECT
CAST(DATE_FORMAT(DATETIME, '%H') AS UNSIGNED) AS 'HOUR', -- ์๊ฐ์ ๊ฐ์ ธ์์, INTํ์ผ๋ก ์ถ๋ ฅ
COUNT(DATETIME) AS 'COUNT'
FROM
ANIMAL_OUTS
GROUP BY
HOUR
HAVING
HOUR
BETWEEN 9
AND 19;
๋๋
SELECT
CAST(SUBSTRING(DATETIME,12,2) AS UNSIGNED) AS 'HOUR',
COUNT(DATETIME) AS 'COUNT'
FROM
ANIMAL_OUTS
GROUP BY
HOUR
HAVING
HOUR
BETWEEN 9
AND 19;
4. ์ ์ ์๊ฐ ๊ตฌํ๊ธฐ(2) |
[์ ๋ต ์ ์ด๋์]
-- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์(๋ฉ์ง ์ ๋ต ์ฝ๋๋ฅผ ๋ฐ๊ฒฌํด์ ๊ธฐ๋กํด๋์)
SET @HOUR_INCLUDE_ZERO = -1;
SELECT
(@HOUR_INCLUDE_ZERO := @HOUR_INCLUDE_ZERO+1) AS 'HOUR',
(SELECT
COUNT(*)
FROM
ANIMAL_OUTS
WHERE
HOUR(DATETIME) = @HOUR_INCLUDE_ZERO)
AS 'COUNT'
FROM
ANIMAL_OUTS
WHERE
@HOUR_INCLUDE_ZERO < 23;
'โ๏ธ ์ด๋ก > ๋คํธ์ํฌ, ๋ฐ์ดํฐ๋ฒ ์ด์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค/์ฟผ๋ฆฌ๋ฌธ ์ฐ์ต] JOIN (0) | 2019.12.23 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค/์ฟผ๋ฆฌ๋ฌธ ์ฐ์ต] IS NULL (0) | 2019.12.23 |
[ํ๋ก๊ทธ๋๋จธ์ค/์ฟผ๋ฆฌ๋ฌธ ์ฐ์ต] SUM, MAX, MIN (0) | 2019.12.01 |
[ํ๋ก๊ทธ๋๋จธ์ค/์ฟผ๋ฆฌ๋ฌธ ์ฐ์ต] SELECT (0) | 2019.12.01 |
[๋งํฌ] HTTP ์๋ฒ ์๋ต ์ฝ๋ (Response Code) ์ ๋ฆฌ_1 (0) | 2019.11.22 |