Žan Fras Žan Fras -4 years ago 80
SQL Question

SQL percentage on one column

I have a database, with a column where I have priorities from 1 to 5 and I have column "Category". I want to calculate percentage of each priority group of sum in each category.

Here you can see my database, where I want to get % of priority for each group


category example

For this example I should get:

Priority 1 - Count 1 - % 50

Priority 5 - Count 1 - % 50

What I tried and didn't work:
enter image description here

I have trouble with query so any help would be appriciated

Answer Source
select priority, count(*) as priority_count, 100 * count(*) / (select count(*) from tasks where category = 'medications') as percent
from tasks 
where category = 'Medications'
group by priority
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download