Skip to content
Advertisement

How to select data from day by day with special time?

I want to select data day by day. Condition: data will be cut the day from 10:00 pm to tomorrow 10 pm. For example:

(2008-12-03 data will be show from 2008-12-02 10:00pm to 2008-12-03 10:00 pm)…

That query shows me all date, but it shows day with all same value.

Advertisement

Answer

You are getting the results duplicated for all days as you are using a CROSS JOIN (written in the legacy syntax using a comma) to join the two SELECT clauses and there is no correlation between those two statements.

You appear to want something like:

or using TO_CHAR( RegTime, 'YYYY-MM-DD' ) instead of TRUNC( RegTime ).

Which, for the sample data:

Would output (for the range 20210101000000 to 20210104000000):

REGTIME             |  T8 | T9 | T10
:------------------ | --: | -: | --:
2021-01-01 00:00:00 | 250 | 42 |  13
2021-01-03 00:00:00 |  23 |  0 |  50
2021-01-02 00:00:00 |  99 | 17 |  24

(Note: the date format depends on the NLS_DATE_FORMAT session parameter [unless you use TO_CHAR].)

db<>fiddle here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement