Date Range Grouping / Aggregation

Get the ABC table with one column. The created date column. Thus, the approximate values ​​are:

 created
 2009-06-18 13:56:00
 2009-06-18 12:56:00
 2009-06-17 14:02:00
 2009-06-17 13:12:23
 2009-06-16 10:02:10

I want to write a query so that the results are as follows:

count    created
2        2009-06-18
2        2009-06-17
1        2009-06-16

Basically count how many records belong to each date but ignore the time.

This is in PL-SQL with Oracle.

Any ideas?

+3
source share
3 answers

select count(*), to_char('YYYY-MM-DD', created) from ABC group by to_char('YYYY-MM-DD', created)

+2
source

The TRUNC function returns DATE DATETIME.

select trunc(created),count(*) from ABC group by trunc(created)
+11
source

, , :

  SELECT trunc( (created - to_date('2000.01.01', 'YYYY.MM.DD'))
                * 24
              ) / 24
         + to_date('2000.01.01', 'YYYY.MM.DD') theDate
       , count(*)
    FROM Layer
GROUP BY trunc( (created - to_date('2000.01.01', 'YYYY.MM.DD'))
                * 24
              ) / 24
         + to_date('2000.01.01', 'YYYY.MM.DD')
ORDER BY 1;

; - , 24, , . * /, (, "7" "* 24" .

+2
source

Source: https://habr.com/ru/post/1710805/


All Articles