Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Week, Month, Year and Life to Date SQL

Sky13Jun 28 2016 — edited Jul 1 2016

Hello everyone,

I have a table that records multiple "Meter Values" for multiple "Stations".  Basically each Station can have up to 62 different Meters being recorded multiple time a day. The table will look like this

STATION_ID  NUMBER

METER_ID NUMBER

METER_VALUE NUMBER

METER_DATE DATE

I need to be able to run a single SQL statement on this multi million row table that will give me something like this.

STATION_ID

METER_ID

TIME_FRAME (This would be Week to Date,  Month to Date, Year to Date and Life Time)

sum(METER_VALUE)

Naturally on a table with many millions of rows I would like to do this with one pass through the table.  I have been working with the group by ROLEUP and CUBE but not getting it.  I can get it for every Week and every Month and Every Year.  But I am after just the current.

Any help would be great.  Thanks.

This post has been answered by Stew Ashton on Jun 29 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2016
Added on Jun 28 2016
14 comments
2,497 views