Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Group by "business days"

Tags:

sql

oracle

plsql

I would like to group a search result by days, but unfortunately, the definition is not a day from midnight to midnight (00:00-24:00), but from 06:00 to 06:00.

Any easy solution? If possible in PL-SQL

like image 236
rdmueller Avatar asked Feb 24 '23 18:02

rdmueller


1 Answers

It should be as simple as this:

GROUP BY TRUNC(DATE - 6/24)

- 6/24 subtracts 6 hours from the datetime in the column DATE and thus all times between 06:00 and 06:00 will be the same day. TRUNC then removes the time part as you only need the date.

like image 89
Daniel Hilgarth Avatar answered Feb 26 '23 07:02

Daniel Hilgarth