I was asked to print the maximum crime along with the count that is taking place in each district which I have to write using only subqueries.
This is the the code that I tried:
select DISTRICT, max(b) max_crime from
(select distinct count(offense_code_group)b,DISTRICT from
dbo.crime
group by DISTRICT,OFFENSE_CODE_GROUP)a
group by DISTRICT
;
By executing this, the output I got was this:
I need the name of the crime(offense_code_group) along with count. Actual output:- district count offense_code_group A1 3496 Larceny