Statistics by time group in oracle

Source: Internet
Author: User


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
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.