0

I have source data like

Name Is_Trget
a Yes
s No
d Yes
f Yes
a Yes
S No

from this source data expected output is

Name Is_Yes Is_No
a 2 0
s 0 2
d 1 0
f 1 0

I need count of Yes and No for a specific Name.

Can someone help on this.

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
asked Oct 23, 2018 at 4:41
0

2 Answers 2

2
SELECT Name, 
 SUM(CASE Is_Trget WHEN 'Yes' THEN 1 ELSE 0 END) Is_Yes,
 SUM(CASE Is_Trget WHEN 'No' THEN 1 ELSE 0 END) Is_No
FROM source
GROUP BY Name;

fiddle

answered Oct 23, 2018 at 5:19
0

Here is another approach using PIVOT

SELECT Name
, Is_Yes = Yes
, Is_No = No
FROM YourTable AS A
PIVOT (COUNT(Is_Trget) FOR Is_Trget IN ([Yes], [No])) AS PivotTable
answered Oct 23, 2018 at 8:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.