October 22, 2024
Chicago 12, Melborne City, USA
SQL

Postgres Get Percentage of Two Counts


I have this query:

select 
id, 
count(*) as total, 
sum(case when code="UNK" then 1 else 0 end) as unk_count
from codes group by

I am trying to add another column for a percentage of the total that is ‘UNK’. How would I go about doing this?

What I was messed with included nested case statements and I am figuring there has to be a more simple way that I cannot figure out



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video