본문으로 건너뛰기
번역된 페이지

이 페이지는 AI의 도움을 받아 영어에서 번역되었습니다. 두 내용이 다를 경우 영어 버전을 기준으로 합니다.

COUNT

리소스의 전체 레코드 수 또는 그룹 내 열에서 NULL이 아닌 인스턴스의 수를 반환합니다.

참고 항목:
[SELECT]


구문​

SELECT COUNT( * | columnExpression ) FROM <multipartIdentifier>
[ GROUP BY groupByColumn ];

인수​

columnExpression 또는 *
열 또는 식입니다. * 기호를 지정하면 리소스 또는 그룹의 모든 레코드 수를 셉니다.

columnExpression의 값 중 하나 이상은 NULL이 아니어야 합니다. 그렇지 않으면 NULL이 반환됩니다.

groupByColumn
요약 또는 집계 작업을 수행하는 데 사용되는 하나 이상의 열입니다. GROUP BY 절은 열 그룹당 1행을 반환합니다.

반환 값​

개수를 나타내는 정수를 반환합니다.


예제​

전체 리소스의 행 수 반환​

SELECT count(*) as num_instances
FROM google.compute.instances
WHERE project = 'stackql-demo'
AND zone = 'australia-southeast1-a';

열 식으로 그룹화된 행 수 반환​

SELECT tags, count(*) as num_instances
FROM google.compute.instances
WHERE project = 'stackql-demo'
AND zone = 'australia-southeast1-a'
GROUP BY json_extract(tags, '$.instanceType');

COUNT 함수를 윈도우 함수로 사용하여 누적 개수 계산​

-- Track cumulative issue counts over time
SELECT
number,
title,
state,
created_at,
COUNT(*) OVER (ORDER BY created_at) as cumulative_issues,
COUNT(*) OVER (PARTITION BY state ORDER BY created_at) as cumulative_by_state
FROM github.issues.issues
WHERE owner = 'stackql'
AND repo = 'stackql'
ORDER BY created_at;

자세한 내용은 https://www.sqlite.org/lang_aggfunc.html#count 문서를 참조하세요.