반응형
MySQL 쿼터별로 그룹핑 리포팅
QUARTER() 함수
SELECT YEAR(leaddate) AS year ,QUARTER(leaddate) AS quarter ,COUNT(jobid) AS jobcount FROM jobs WHERE contactid = '19249' GROUP BY YEAR(leaddate), QUARTER(leaddate) ORDER BY YEAR(leaddate), QUARTER(leaddate)
예제
SELECT
YEAR(A.BIZ_DATE) AS YEAR
,CASE QUARTER(A.BIZ_DATE)
WHEN 1 THEN "Q1"
WHEN 2 THEN "Q2"
WHEN 3 THEN "Q3"
WHEN 4 THEN "Q4"
END AS date /* QUARTER */
,COUNT(P.PURCHASE_AMT) AS NumOfSales
FROM SALE_HD A
INNER JOIN PAYMENT P ON A.SALE_ID = P.SALE_ID
WHERE A.BIZ_DATE BETWEEN "20200101" AND "20211014"
GROUP BY YEAR(A.BIZ_DATE), QUARTER(A.BIZ_DATE)
ORDER BY YEAR(A.BIZ_DATE), QUARTER(A.BIZ_DATE);
============================
YEAR date NumOfSales
2021 Q3 1579
2021 Q4 268
(참고: MSSQL에서는 쿼터별 함수는 DATEPART(QUARTER, A.BIZ_DATE)로 사용합니다)
[ MySQL 개발 문서 ]
Returns the quarter of the year for date
, in the range 1
to 4
.
mysql> SELECT QUARTER('2008-04-01'); -> 2
[ Quarter - Q1, Q2, Q3, Q4 쿼러란 무엇인가? ]
What is a 'Quarter - Q1, Q2, Q3, Q4'
A quarter (Q1, Q2, Q3, Q4) is a three-month period on a financial calendar that acts as a basis for the reporting of earnings and the paying of dividends. A quarter refers to one-fourth of a year and is typically expressed as "Q." The four quarters that make up the year are: January, February and March (Q1); April, May and June (Q2); July, August and September (Q3); and October, November and December (Q4). A quarter is often shown with its relevant year, as in Q1 2015 or Q1/15, which represents the first quarter of the year 2015.
Read more: Quarter - Q1, Q2, Q3, Q4 Definition | Investopedia http://www.investopedia.com/terms/q/quarter.asp#ixzz4Lmn6QX65
Follow us: Investopedia on Facebook
반응형
'DB관련 > MySQL' 카테고리의 다른 글
MySQL DB Table OPTIMIZE 저장 공간 줄이기 (Storage Shrink 처리) (0) | 2017.11.01 |
---|---|
[펌]MySQL 쓰면서 하지 말아야 할 것 17가지 (0) | 2017.08.25 |
MySQL 프로세스 리스트 보기 , 프로세스 죽이기. (0) | 2017.04.20 |
DB명 Table명 대소문자 구분 처리하기 (대소문자 구분 OS에서만 가능) (0) | 2016.11.08 |
MySQL 인코딩 UTF-8 설정하기 (한글 깨짐 문제) (0) | 2016.05.17 |
SQLyog 한글 깨짐 방지 (0) | 2015.07.21 |
Mysql 수동 commit 처리 ( auto_commit 막기) (0) | 2014.11.01 |
YEAR() MONTH() 함수로 WHERE 검색 조건에 년, 월 기준으로 검색 조건 결과 얻는 방법 (0) | 2014.10.31 |
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)
(로그인하지 않으셔도 가능)