Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

merge two rows within a group SQL sript

$
0
0

Hi I have a script below which groups the client together:

SQL
SELECTClient,COUNT(*)ASCosts,SUM(CASEWHENTrainclass='1'THEN1ELSE0END)ASFirstClass,SUM(CASEWHENTrainclass='2'THEN1ELSE0END)ASSecondClass,SUM(Seats)ASSeatsFROMdbo.PreviousMonthReportGROUPBYClient

This generates the below:

Text
Client Costs FirstC SecondC Seats Train1 4 13 14 81 AA_2 1 0 13 70 Train3 4 0 55 60 AA_4 1 18 37 41 Train2 1 33 99 44 BC_3 18 0 08 48 VR_1 1 11 61 25 

However, is there a good way to add both the AA_2 and AA_4 together as one value so it would show the following:

Text
Client Costs FirstC SecondC Seats Train1 4 13 14 81 AA 2 18 50 111 Train3 4 0 55 60 Train2 1 33 99 44 BC_3 18 0 08 48 VR_1 1 11 61 25 

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>