Oracle queries the number of days in a time period

Source: Internet
Author: User

1:oracle Query The total number of messages sent per day for a certain period of time

Select Tab.tday,
(select COUNT (1) from T_msgsendrecode m where trunc (m.sendtime) = To_date (Tab.tday, ' yyyy-mm-dd '))
From (

SELECT * FROM (
Select To_char (Add_months (Last_day (' 2015-6-2 ', ' yyyy-mm-dd ') +1,-1), ' Yyyy-mm-dd ') as Tday from dual
UNION ALL
Select To_char (Add_months (Last_day (' To_date (' 2015-6-2 ', ' yyyy-mm-dd ')) +1,-1) + rownum, ' yyyy-mm-dd ') as Tday
From dual
Connect by RowNum <= (last_day to_date (' 2015-6-2 ', ' yyyy-mm-dd ')-Add_months (Last_day (' 2015-6-2 ', ' Yyyy-mm-dd ')) +1,-1))
)

) tab

2: Query two days of data

Select RowNum dis from (
Select Max (to_date (' 2015-6-30 ', ' Yyyy-mm-dd ')-to_date (' 2015-6-1 ', ' yyyy-mm-dd ') +1 as gap from dual
) Connect by RowNum <= Gap

Oracle queries the number of days in a time period

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.