Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
akamole
Starting Member
17 Posts |
Posted - 2014-02-24 : 10:09:20
|
Table with water consumtion per month and customer.I want to sum up total consumption per customer with a select statement |
|
maggie21620
Starting Member
27 Posts |
Posted - 2014-02-24 : 11:06:32
|
i am looking for the same type of function let me know what you get please.none |
|
|
maunishq
Yak Posting Veteran
71 Posts |
Posted - 2014-02-24 : 11:49:48
|
SELECT Customer, SUM(Consumption) AS Total_ConsumptionFROM Table_NameGROUP BY CustomerORDER BY Customer=============================================================If you are using SQL SERVER 2012, then you can also do:SELECT Customer, SUM(Consumption) OVER(Partition by Customer ORDER BY Customer) AS Total_ConsumptionFROM Table_NameI hope this helps.!!_(M)_!! |
|
|
akamole
Starting Member
17 Posts |
Posted - 2014-02-25 : 01:54:14
|
SELECT Customer, SUM(Consumption) AS Total_ConsumptionFROM Table_NameGROUP BY CustomerORDER BY CustomerThis worked great, thank you! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-27 : 02:55:56
|
quote: Originally posted by maunishq SELECT Customer, SUM(Consumption) AS Total_ConsumptionFROM Table_NameGROUP BY CustomerORDER BY Customer=============================================================If you are using SQL SERVER 2012, then you can also do:SELECT Customer, SUM(Consumption) OVER(Partition by Customer ORDER BY Customer) AS Total_ConsumptionFROM Table_NameI hope this helps.!!_(M)_!!
You can use it for all versions from sql 2005 with a changeSELECT DISTINCT Customer, SUM(Consumption) OVER(Partition by Customer) AS Total_ConsumptionFROM Table_Name ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|