My (currently) favorite SQL technique
SUM with CASE WHEN
So we have this dataset about crimes in London.
Let's calculate what was the % of crimes categorised as 'Violence Against the Person' compared to all the crime types.
,round(sum(case when major_category = 'Violence Against the Person' then 1 else 0 end)
/sum(case when major_category = 'Violence Against the Person' then 1 else 1 end),2) as result
Checking it:
Divide the 2 numbers, round it, and the result is the same.
Methods were kinda convoluted, but I love them.