I have a table with 5 columns ReportId, Date, Area, BuildingName, Amount.
Sample data looks like this :
-------------------------------------------------------
ReportId | Date | Area | BuildingName | Amount
-------------------------------------------------------
1 | 01/01/2013 | S1 | A1-01 | 5
2 | 01/01/2013 | S1 | A1-03 | 5
3 | 01/01/2013 | S2 | A1-05 | 4
4 | 02/01/2013 | S2 | A1-05 | 7
5 | 02/01/2013 | S2 | A1-03 | 9
6 | 03/01/2013 | S1 | A1-03 | 2
7 | 04/01/2013 | S2 | A1-02 | 6
8 | 05/01/2013 | S1 | A1-01 | 7
9 | 06/01/2013 | S1 | A1-02 | 5
10 | 06/01/2013 | S1 | A1-05 | 8
11 | 06/01/2013 | S1 | A1-07 | 5
I need to write a query to get the result like this :
-----------------------------------------------------
Date | Area | BuildingName | Amount | Sum
-----------------------------------------------------
01/01/2013 | S1 | A1-01 | 5 | 12
01/01/2013 | S1 | A1-03 | 5 | 7
01/01/2013 | S2 | A1-05 | 4 | 11
Date value passed as a parameter to the query.
"Area", "BuildingName", "Amount" are records which have the same "Date".
"Sum", is Sum of All "Amount" in the table where has the same "Area" And "BuildingName" in the result of query.
I searched much, but I can't get anything about this ...
Aucun commentaire:
Enregistrer un commentaire