Skip to content
Advertisement

SQL Query calculating two additional columns

I have a table which gets populated daily with database size. I need to modify the query where I can calculate daily growth and weekly growth.

Current Output

enter image description here

I would like to add two additional columns which would be Daily Growth (DB_SIZE sysdate – DB_SIZE (sysdate -1)) Weekly Growth (DB_SIZE sysdate – DB_SIZE (sysdate -7))

Need some help constructing the SQL for those two additional columns. Any help will be greatly appreciated.

Thanks,

Advertisement

Answer

One option is to use LAG analytic function to calculate daily growth and correlated subquery (within the SELECT statement) for weekly growth.

For example:

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