일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- windows10
- 자본주의
- sql developer
- 크롤링
- vscode
- tensorflow
- 윈도우10
- MSSQL
- django
- PYTHON MSSQL
- 장고
- M2M
- Python
- 텐서플로우
- c#
- scrapy
- 오라클
- oracle
- 티스토리 초대장
- matplot
- pymssql
- rs422
- MX Component
- MSSQL PYTHON
- Serial
- Visual Studio Code
- rs485
- 딥러닝
- MEAN Stack
- 파이썬
Archives
- Today
- Total
안까먹을라고 쓰는 블로그
[MSSQL] 통계(DATEPART) 구하기 (년,분기,월,주간,일 단위) 본문
반응형
-- 년 단위통계
SELECT TOP 10 MAX(DATEPART(YYYY, SUBL_DATE)) AS YYYY, MAX(DATEPART(mm, SUBL_DATE)) AS mm, MAX(DATEPART(DD, SUBL_DATE)) AS DD, MECUST_NM, COUNT(*) AS COUNT FROM CZ_KIDV_TAKEBACK
group by DATEPART(YYYY, SUBL_DATE), MECUST_NM
ORDER BY MAX(DATEPART(YYYY, SUBL_DATE)) ASC, MAX(DATEPART(mm, SUBL_DATE)) ASC, MAX(DATEPART(DD, SUBL_DATE)) ASC, MECUST_NM asc
-- 분기별 통계
SELECT TOP 10 MAX(DATEPART(YYYY, SUBL_DATE)) AS YYYY, DATEPART(QUARTER, SUBL_DATE) AS QUARTER , MECUST_NM, COUNT(*) AS COUNT FROM CZ_KIDV_TAKEBACK
group by DATEPART(QUARTER, SUBL_DATE), MECUST_NM
ORDER BY MAX(DATEPART(YYYY, SUBL_DATE)) ASC, MAX(DATEPART(QUARTER, SUBL_DATE)) ASC, MECUST_NM asc
-- 월 단위통계
SELECT TOP 10 MAX(DATEPART(YYYY, SUBL_DATE)) AS YYYY, DATEPART(mm, SUBL_DATE) AS mm, MECUST_NM, COUNT(*) AS COUNT FROM CZ_KIDV_TAKEBACK
group by DATEPART(mm, SUBL_DATE), MECUST_NM
ORDER BY MAX(DATEPART(YYYY, SUBL_DATE)) ASC, MAX(DATEPART(mm, SUBL_DATE)) ASC, MECUST_NM asc
-- 주간별 통계
SELECT TOP 10 MAX(DATEPART(YYYY, SUBL_DATE)) AS YYYY, MAX(DATEPART(mm, SUBL_DATE)) AS mm, DATEPART(ww, SUBL_DATE) AS ww, MECUST_NM, COUNT(*) AS COUNT FROM CZ_KIDV_TAKEBACK
group by DATEPART(ww, SUBL_DATE), MECUST_NM
ORDER BY MAX(DATEPART(YYYY, SUBL_DATE)) ASC, MAX(DATEPART(mm, SUBL_DATE)) ASC, DATEPART(ww, SUBL_DATE) ASC, MECUST_NM asc
-- 일 단위통계
SELECT TOP 10 MAX(DATEPART(YYYY, SUBL_DATE)) AS YYYY, MAX(DATEPART(mm, SUBL_DATE)) AS mm, DATEPART(DD, SUBL_DATE) AS DD, MECUST_NM, COUNT(*) AS COUNT FROM CZ_KIDV_TAKEBACK
group by DATEPART(DD, SUBL_DATE), MECUST_NM
ORDER BY MAX(DATEPART(YYYY, SUBL_DATE)) ASC, MAX(DATEPART(mm, SUBL_DATE)) ASC, DATEPART(DD, SUBL_DATE) ASC, MECUST_NM asc
끝~
반응형
'DataBase > MS SQL' 카테고리의 다른 글
[MSSQL] OPENQUERY - BETWEEN 성능??? (Feat. ORACLE) (0) | 2022.08.12 |
---|---|
[MSSQL] 중복확인 및 제거방법 (0) | 2022.08.11 |
[MSSQL] OPENQUERY 예제 쿼리 (0) | 2022.08.08 |
[MSSSQL] SQL Server의 OPENQUERY 함수 이해 (0) | 2022.07.01 |
[MSSQL] LinkedServer 쿼리 오류(ORA-01403: 데이터를 찾을 수 없음 (0) | 2022.07.01 |
Comments