I have a table like this,Consider i have around 5 million records.
Transaction id|Amount|CustomerId|date
1 | 100 | 20 |1/1/2012
2 | 230 | 30 |2/2/2012
3 | 320 | 20 |2/3/2012
etc...
How can i find total amount for last 5 transactions of each customer in each quarter in 2012?
Output: Quarter|Customerid|totalAmount
1 | 20 | 40000
1 | 30 | 300000
2 ...etc...
Please write an efficient method..
You should post the ddl.But You can try something like this.It should work..
If you want someone else to write efficient queries for you.Then you have to do some hard work by providing the ddl,indexes etc and some sample data and what approaches you have used till now.