Finding Distinct Value using SQL

后端 未结 3 494
孤独总比滥情好
孤独总比滥情好 2021-01-26 17:11

Show the titles and the award amounts of 20 awards that contain words discover, discoverer, discovery, discovered, and discovering in their abstracts.

My query:

3条回答
  •  伪装坚强ぢ
    2021-01-26 18:07

    This query assumes distinct awards per pi.

    SELECT COUNT(distinct award), pi 
    FROM [tablename] 
    GROUP BY pi 
    ORDER BY COUNT(distinct award) DESC
    

    States with top number of awards.

    SELECT TOP 20 COUNT(distinct award), state
    FROM [tablename]
    GROUP BY state
    ORDER BY COUNT(distinct award)
    

    Remove the TOP 20 if you are not using T-SQL.

提交回复
热议问题