Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can try your query in a subquery:</p> <pre><code>select referralName, count(id_referral) gCount From (SELECT CASE (id_referral ) WHEN 1 THEN 'Treatment' WHEN 2 THEN 'Medication' WHEN 3 THEN 'Medication' WHEN 4 THEN 'Diagnosis / Tests' WHEN 5 THEN 'Diagnosis / Tests' ELSE 'Other' END referralName , id_referral from referralDetails ) AS TABLE1 GROUP BY Test </code></pre> <p>or You can TRY this one which is return column group count with extra column</p> <pre><code>SELECT * FROM (SELECT CASE (id_referral ) WHEN 1 THEN 'Treatment' WHEN 2 THEN 'Medication' WHEN 3 THEN 'Medication' WHEN 4 THEN 'Diagnosis / Tests' WHEN 5 THEN 'Diagnosis / Tests' ELSE 'Other' END referralName, ROW_NUMBER() OVER (PARTITION BY (CASE (id_referral ) WHEN 1 THEN 'Treatment' WHEN 2 THEN 'Medication' WHEN 3 THEN 'Medication' WHEN 4 THEN 'Diagnosis / Tests' WHEN 5 THEN 'Diagnosis / Tests' ELSE 'Other' END ) ORDER BY id_referral ) AS NO, COUNT(id_referral) OVER(PARTITION BY (CASE (id_referral ) WHEN 1 THEN 'Treatment' WHEN 2 THEN 'Medication' WHEN 3 THEN 'Medication' WHEN 4 THEN 'Diagnosis / Tests' WHEN 5 THEN 'Diagnosis / Tests' ELSE 'Other' END )) AS gCount, * FROM referralDetails) AS TABLE1 WHERE no =1 </code></pre> <p>or</p> <pre><code>SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY referralName ORDER BY id_referral) AS NO, COUNT(id_referral) OVER(PARTITION BY referralName) AS gCount, * FROM (SELECT CASE (id_referral % 100 ) WHEN 1 THEN 'Treatment' WHEN 2 THEN 'Medication' WHEN 3 THEN 'Medication' WHEN 4 THEN 'Diagnosis / Tests' WHEN 5 THEN 'Diagnosis / Tests' ELSE 'Other' END AS referralName ,* FROM dbo.referralDetails) AS T1)AS T2 WHERE No = 1 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload