SQL 고득점 Kit - GROUP BY
5939 단어 programmerssqlprogrammers
GROUP BY
고양이와 개는 몇 마리 있을까
SELECT ANIMAL_TYPE, count(ANIMAL_ID) as count
FROM ANIMAL_INS
WHERE ANIMAL_TYPE IN('Cat','Dog')
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE
동명 동물 수 찾기
WITH TEMP_TABLE AS (
SELECT NAME, COUNT(ANIMAL_ID) AS COUNT
FROM ANIMAL_INS
WHERE NAME IS NOT NULL
GROUP BY NAME
ORDER BY NAME)
SELECT *
FROM TEMP_TABLE
WHERE COUNT > 1
SELECT NAME, COUNT(ANIMAL_ID)
FROM ANIMAL_INS
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME
입양 시각 구하기(1)
SELECT hour(DATETIME) as HOUR, COUNT(ANIMAL_ID) as COUNT
FROM ANIMAL_OUTS
GROUP BY hour(DATETIME)
HAVING HOUR BETWEEN 9 AND 19
ORDER BY HOUR;
입양 시각 구하기(2)
SET @HOUR = -1;
SELECT @HOUR := @HOUR + 1 AS HOUR,
(SELECT COUNT(*)
FROM ANIMAL_OUTS
WHERE HOUR(DATETIME)=@HOUR) AS COUNT
FROM ANIMAL_OUTS
GROUP BY HOUR
HAVING HOUR BETWEEN 0 AND 23;
Author And Source
이 문제에 관하여(SQL 고득점 Kit - GROUP BY), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@wooyo/programmers-SQL-고득점-Kit-GROUP-BY
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
SELECT ANIMAL_TYPE, count(ANIMAL_ID) as count
FROM ANIMAL_INS
WHERE ANIMAL_TYPE IN('Cat','Dog')
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE
WITH TEMP_TABLE AS (
SELECT NAME, COUNT(ANIMAL_ID) AS COUNT
FROM ANIMAL_INS
WHERE NAME IS NOT NULL
GROUP BY NAME
ORDER BY NAME)
SELECT *
FROM TEMP_TABLE
WHERE COUNT > 1
SELECT NAME, COUNT(ANIMAL_ID)
FROM ANIMAL_INS
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME
SELECT hour(DATETIME) as HOUR, COUNT(ANIMAL_ID) as COUNT
FROM ANIMAL_OUTS
GROUP BY hour(DATETIME)
HAVING HOUR BETWEEN 9 AND 19
ORDER BY HOUR;
SET @HOUR = -1;
SELECT @HOUR := @HOUR + 1 AS HOUR,
(SELECT COUNT(*)
FROM ANIMAL_OUTS
WHERE HOUR(DATETIME)=@HOUR) AS COUNT
FROM ANIMAL_OUTS
GROUP BY HOUR
HAVING HOUR BETWEEN 0 AND 23;
Author And Source
이 문제에 관하여(SQL 고득점 Kit - GROUP BY), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@wooyo/programmers-SQL-고득점-Kit-GROUP-BY저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)