One row per WOID and Measure counts based on Category values.
Then WOIDCount
will always be '1' for each row right?
If I understood right, then in Viorel's answer, it is no need to count(WOID) as WOIDCount
, just 1 as WOIDCount
will be fine.
Also, you could try this query using PIVOT:
SELECT WOID,
1 AS WOIDCount,
[A] AS ACount,
[B] AS BCount,
[C] AS CCount,
[D] AS DCount
FROM (SELECT WOID,Category,Description FROM @Sample)S
PIVOT(COUNT(Description) FOR Category IN([A],[B],[C],[D]))P
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.