I have one problem in postgreSQL.
This is my table (This table does not showing all data in Image)
what is my requirement is
Step 1 : find count of value (this is a column in table) Order by value for today date. So It will be like this and I did it(no difficulty)
Step 2 : find count of value for last 30 days starting from today. I am stuck here. Also one another thing is included in this step --
Example : today has 10 count for a value - kash, this will be 10x30, yesterday had 4 count for the same value , so will be 4x29, so the total sum would be
(10x30) + (4x29) = 416.
This calculation is calculated for each and every value.
This loop execute for 3o times (as I said before last 30 days starting from today). Take today as thirstiest day.
Query will just need to return two columns with value and sum, ordered by the sum
Please help me
sum(...) OVER (...)
i.e. use sum as a window function. – Craig Ringer Apr 4 '14 at 1:47