उपयोग करें:
SELECT x.company,
x.year,
x.annual_total
x.annual_total / y.total AS percentage
FROM (SELECT t.company,
YEAR(t.date) as year,
COUNT( * ) as annual_total
FROM TABLE t
WHERE t.company IN ('Medtronic', 'Private')
GROUP BY YEAR( t.date ) ) x
JOIN (SELECT t.company,
COUNT(*) 'total'
FROM TABLE t
WHERE t.company IN ('Medtronic', 'Private')
GROUP BY t.company) y ON y.company = x.company
यदि आप विशेष दशमलव स्थानों के साथ प्रतिशत चाहते हैं, तो उपयोग करें:
CAST(x.annual_total / y.total AS DECIMAL(2,2)) AS percentage
जाँच करें कि यह आपके द्वारा अपेक्षित प्रति कंपनी गिनती देता है:
SELECT t.company,
COUNT(*) 'total'
FROM TABLE t
WHERE t.company IN ('Medtronic', 'Private')
GROUP BY t.company