SQL..Sum two rows

Posted by Cha on Stack Overflow See other posts from Stack Overflow or by Cha
Published on 2011-06-30T14:56:56Z Indexed on 2011/06/30 16:22 UTC
Read the original article Hit count: 653

Filed under:
|

Sample data:

LOCATION   NAME   LABEL1   LABEL2 SERVICE TIME
NY         Andrew    A       B      HOUSE  2555
NY         Andrew    A       B      CAR    35
NJ         Copley    C       A      HOUSE  1025
NY         Copley    A       B      HOUSE  650
VA         Dalton    D       C      PET    25

What I want to do ias add another column where in it shows sum(Time) of rows with same data except for the Service.Also, the services that I need are only the sum of car and house.Is this possible? If not can you help me with the right query

Sample output I need:

LOCATION   NAME   LABEL1   LABEL2 SERVICE TIME     SUM
NY         Andrew    A       B      HOUSE  2555    **2590**
NY         Andrew    A       B      CAR    35
NJ         Copley    C       A      HOUSE  1025    1025
NY         Copley    A       B      HOUSE  650     650

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sum