Finding Distinct Value using SQL

后端 未结 3 501
孤独总比滥情好
孤独总比滥情好 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:05

    You are missing the single quotes around your criteria, you are only looking for words that start with "discov", your order by clause is in the wrong place, and you are using a count() expression without grouping by the other non-aggregate fields. In order to fix this and look for words containing "discov", use this:

    SELECT title, abstract, count(award),  
    FROM table 
    WHERE abstract 
    LIKE '%discov%' 
    GROUP BY title, abstract
    ORDER BY count(award) 
    LIMIT 20
    

    If you truly did mean to just look for words starting with "discov", then use this:

    SELECT title, abstract, count(award),  
    FROM table 
    WHERE abstract 
    LIKE 'discov%'
    GROUP BY title, abstract
    ORDER BY count(award) 
    LIMIT 20
    

提交回复
热议问题