This is a follow-up to my previous question: Get records for last 10 dates
I have to generate reports for all books of a store along with sold count (if any) for the last N dates, by passing storeId.
BOOK Book Sold Store
------------ -------------------- ----------------
Id Name SID Id Bid Count Date SID Name
1 ABC 1 1 1 20 11/12/2015 1 MNA
2 DEF 1 2 1 30 12/12/2015 2 KLK
3 DF2 2 3 2 20 11/12/2015 3 KJH
4 DF3 3 4 3 10 13/12/2015
5 GHB 3 5 4 5 14/12/2015
The number of days N is supplied by the user. This is the expected output for the last 4 dates for storeId -1,2 & 3.
BookName 11/12/2015 12/12/2015 13/12/2015 14/12/2015
ABC 20 30 -- --
DEF 20 -- -- --
DF2 -- -- 10 --
DF3 -- -- -- 5
GHB -- -- -- --
If the user passes 5 than data for the last 5 days shall be generated, starting date as 14/12/2015.
I am using Postgres 9.3.