1.0 PLSQL date data packet statistics

1. Monthly amount of data

1.1 Single table statistics

SELECT TO_CHAR(A.DATE, 'YYYY/MM') AS 月份, SUM(1) AS 数量
  FROM TABLE A
 GROUP BY TO_CHAR(CI.CREATE_DATE, 'YYYY/MM')
 ORDER BY 月份;

1.2 multi-table associated with

SELECT TO_CHAR(A.DATE, 'YYYY/MM') AS 月份, SUM(1) AS 数量
  FROM TABLE A, TABLE B
 WHERE A.ID= B.ID
 GROUP BY TO_CHAR(CI.CREATE_DATE, 'YYYY/MM')
 ORDER BY 月份;

to sum up:

1. The conversion date, the date format to be used when conditions are converted into a string TO_CHAR verified, then the date format is defined with the corresponding date taken.

 按年:TO_CHAR(A.DATE,'YYYY')

 Quarterly (3 months): TO_CHAR (A.DATE, 'Q')

2. Group field consistent with the query field, the number of summation

3. Sort: Default ascending (ASC) ASC ASC is meant ascend, DESC (desc descending means is descend)

What should pay attention to system date format (eg: yyyy-mm)

 

Guess you like

Origin www.cnblogs.com/Smileing/p/12103570.html