sql server - SQL Count Types and return all items under those counts -


i using following sql query count of several item types under 20. trying extract rows fall category. there other types have counts on 20 don't particularly care those.

 select item_type, count(item_number) "count"      total_collection       group item_type      having count(item_type) < 20; 

result:

c15     9 c1srt   1 ca7     7 d4s5m   10 d4s7m   4 d5s7e   2 

for example: have 9 counts fall c15.

select ltrim(rtrim(item_type)) as item_type, item_status, item_number from total_collection  item_type in ('c15')  c15 2   000540176 c15 2   000384552 c15 2   000452976 c15 2   000372632 c15 2   000573561 c15 2   000592110 c15 2   000465054 c15 2   000394784 c15 2   000400305 

i trying combine results of first query, give me complete list of types. fields found in 1 table.

i tried find answer question, wasn't able locate one. if somehow missed this, apologize duplicate. still pretty new sql.

try this:

select ltrim(rtrim(item_type)) item_type, item_status, item_number total_collection  item_type in (     select item_type     total_collection      group item_type     having count(item_type) < 20 ) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -