0

I would like to convert a COUNT which includes PARTITION BY in SQL Server. Desired output would be percentage to 2 decimal places with '%' symbol included (78.48% instead of 78, for example).

Here is what I have:

(((100 * COUNT(STC_GRADE)) / SUM(COUNT(STC_GRADE)) OVER (PARTITION BY STC_COURSE_NAME 
                                                         ORDER BY STC_COURSE_NAME))) AS Percentage

Any help would be greatly appreciated!

Dale K
  • 25,246
  • 15
  • 42
  • 71
KLR
  • 51
  • 7
  • Integer division always returns an integer result. Convert one of your values to a decimal. – Dale K Feb 02 '21 at 20:35
  • Does this answer your question? [Decimal values in SQL for dividing results](https://stackoverflow.com/questions/4834973/decimal-values-in-sql-for-dividing-results) – Dale K Feb 02 '21 at 20:36
  • Unfortunately I am unsure how to 'write' it out with the OVER (PARTITION BY....) part in my query. – KLR Feb 02 '21 at 20:38
  • 1
    Just change 100 to 100.00 :) – Dale K Feb 02 '21 at 20:40
  • Thank you so much Dale! That will get me by for right now! – KLR Feb 02 '21 at 20:42

0 Answers0