In oracle, ASK_TIME ATM_NUMBER 2012-01-01 2 2012-02-01 4 2012-05-01 6 2012-08-01 8 1. grouping BY year www.2cto.com SELECT (to_char (ASK_TIME, 'yyyy') as year, (sum (ATM_NUMBER) as number of ATMs FROM TB_KFWH_WORKREPORT group by to_char (ASK_TIME, 'yyyy ') ---------------------------------------------------------------------- the number of ATMs in a year is 2012. 2. SELECT (to_char (ASK_TIME, 'yyyy-mm') as month BY month, (sum (ATM_NUMBER) as number of ATMs FROM TB_KFWH_WORKREPORT group by to_char (ASK_TIME, 'yyyy-mm') --------------------------------------------------------------------- number of monthly ATMs: www.2cto.com 2012-01 2 2012-02 4 2012-05 6 2012-08 8 3. SELECT (to_char (ASK_TIME, 'yyyy-iw') as week, (sum (ATM_NUMBER) as number of ATMs FROM TB_KFWH_WORKREPORT group by to_char (ASK_TIME, 'yyyy-iw') 4. SELECT (to_char (ASK_TIME, 'yyyy-Q') as quarter, (sum (ATM_NUMBER) as number of ATMs FROM TB_KFWH_WORKREPORT group by to_char (ASK_TIME, 'yyyy-Q') Number of ATMs in the quarter 2012-1 6 2012-2 6 2012-3 8 or www.2cto.com SELECT (to_char (ASK_TIME, 'yyyy') as year, sum (decode (to_char (ASK_TIME, 'mm'), '01', ATM_NUMBER, '02', ATM_NUMBER, '03', ATM_NUMBER, '0') as the first season, sum (decode (to_char (ASK_TIME, 'mm'), '04 ', ATM_NUMBER, '05', ATM_NUMBER, '06', ATM_NUMBER, '0') as second quarter, sum (decode (to_char (ASK_TIME, 'mm'), '07 ', ATM_NUMBER, '08', ATM_NUMBER, '09', ATM_NUMBER, '0') as Quarter 3, sum (decode (to_char (ASK_TIME, 'mm'), '10', ATM_NUMBER, '11', ATM_NUMBER, '12', ATM_NUMBER, '0 ')) as Season 4 FROM TB_KFWH_WORKREPORT group by to_char (ASK_TIME, 'yyyy') ------------------------------------------------------ Season 1 season 2 Season 4 season 2012 6 8 0