Oracle count data by Days ____oracle

Source: Internet
Author: User
When you use GROUP by Cratetime, but one day there is no data, there will be no data one day.

So using the following SQL, you can count out every day.

        Select
            To_date (' 2015-06-01 ', ' yyyy-mm-dd ') +level-1 as time 
        from dual  connect by to_date (' 2015-06-01 ', ' yyyy-mm-dd ') + Level-1 <= to_date (' 2015-06-04 ', ' yyyy-mm-dd ');
      
        Select 
            (to_date (' 2015-06-01 ', ' yyyy-mm-dd ') +level-1) as time from 
        dual connect by Level <= To_date (' 2015-06-04 ', ' yyyy-mm-dd ')-to_date (' 2015-06-01 ', ' yyyy-mm-dd ') + 1;

The results of the query are as follows:

Time
2015-6-1
2015-6-2
2015-6-3
2015-6-4

Then use the left on link to query the statistics:

Select C_TIME,NVL (totaluser,0) as Total_user from (
        select   (to_date (' 2015-06-01 ', ' yyyy-mm-dd ') +level-1) as C_  dual Connect by Level <= to_date (' 2015-06-11 ', ' yyyy-mm-dd ')-to_date (' 2015-06-01 ', ' yyyy-mm-dd ') + 1
  ) a LEFT join (
          select Trunc (u.create_time) as Create_time,count (*) as totaluser from T_user u GROUP by trunc (U.crea Te_time)
        


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.