sql server - MS SQL having clause issue -


i have 2 columns

item    |   category  apple      fruit orange     fruit potatoes   vegetables 

required output:

fruit

i trying name of highest category in terms of quantity fruit. wrote mysql query works on mysql. same query throws error on ms sql server. hint appreciated.

select cat (select count(category) total,category cat test group category) s1 group s1.total,s1.cat having max(s1.total) 

i empty result when run this. similar query created runs fine on mysql:

select s2.cats (select s1.cat cats, max(s1.counts) countings (select count(category) counts, category cat test group category) s1) s2 

error message is: msg 4145, level 15, state 1, line 1 expression of non-boolean type specified in context condition expected, near ')'.

i want avoid using top

something this? pretty ugly avoids top. also, return items have max count, not arbitrary one.

assuming table [food] column category:

select category food group category having count(*) =  (select max(cnt) (select count(*) cnt food group category) subq) 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -