none
Group by - SQL Server

    Question

  • Hi,

    I have following table. I need to find the total for ElectronicSale and GrocerySale for all customers which in this case would be Electronics:55 and GrocerySale: 55

    CustomerID ElectronicSale GrocerySale SaleDate
    1 5 5 10/1/13 1:57 PM
    1 5 5 10/2/13 1:57 PM
    1 5 5 10/3/13 1:57 PM
    1 5 5 10/4/13 1:57 PM
    1 5 5 10/6/13 1:57 PM
    2 10 10 10/1/13 1:57 PM
    2 10 10 10/2/13 1:57 PM
    2 10 10 10/3/13 1:57 PM
    2 10 10 10/4/13 1:57 PM
    2 10 10 10/5/13 1:57 PM

    Thanks a lot in advance

    • Moved by SSISJoost Tuesday, October 08, 2013 8:29 PM Not SSIS related
    Sunday, October 06, 2013 2:48 PM

Answers

  • Select sum(ElectronicSale) as ElectronicSale, sum(GrocerySale) as GrocerySale from table

    • Marked as answer by Ali_Hum Monday, October 07, 2013 3:34 AM
    Sunday, October 06, 2013 2:55 PM
  • Select CustomerID, SUM(ElectronicSale), SUM(GrocerySale) From tableName Group By CustomerID

    • Proposed as answer by SSISJoost Sunday, October 06, 2013 3:48 PM
    • Marked as answer by Ali_Hum Monday, October 07, 2013 3:34 AM
    Sunday, October 06, 2013 3:02 PM

All replies