Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a table Report as below
HTML
Group_Display_Name	Equipment_Display_Name	Parameter Name	Required Pounds	Actual Pounds
SECOND Group	LIME	        AMOUNT_ADDED	0	7245.495605
SECOND Group	LIME	        CHARGE_AMOUNT	7263	0
SECOND Group	METHANOL	AMOUNT_ADDED	0	5714.498047
SECOND Group	METHANOL	CHARGE_AMOUNT	0	0
THIRD Group	LIME	        AMOUNT_ADDED	0	3603.398926
THIRD Group	LIME	        CHARGE_AMOUNT	3625	0
THIRD Group	XYLENE	        AMOUNT_ADDED	0	10177.30566
THIRD Group	XYLENE	        CHARGE_AMOUNT	10070	0


Every group has an equipment with Parameter as Charge Amount and Amount Added.
I want to show these two lines as one line like,
HTML
Second Group    LIME    7236    7245.495605
Second Group   Methanol    0   5714.498047

Column Parameter Name, I do not want to display.

What I have tried:

I tried to use CASE but could not get what I want.
Posted
Updated 4-Jun-18 0:53am

Try this:
SQL
SELECT Group_Display_Name, Equipment_Display_Name, SUM([Required Pounds]) AS RP, SUM([Actual Pounds]) AS AP
FROM YOUR_TABLE
GROUP BY Group_Display_Name, Equipment_Display_Name


Good luck!
 
Share this answer
 
Please try:
SQL
SELECT Group_display_name,Equipment_Display_name,
    SUM(CASE PARAMETER_NAME WHEN 'CHARGE_AMOUNT' THEN required_pounds ELSE 0 END) AS c1,
    SUM(CASE PARAMETER_NAME WHEN 'CHARGE_AMOUNT' THEN 0 ELSE actual_pounds END) AS c2
    FROM data
GROUP BY Group_display_name,Equipment_Display_name
ORDER  by Group_display_name,Equipment_Display_name
 
Share this answer
 
Comments
Maciej Los 4-Jun-18 6:55am    
CASE WHEN is redundant... See my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900