显示20个奖项的标题和奖励金额,其中包含在摘要中发现,发现,发现,发现和发现的单词。
我的查询:
SELECT title, count(award), abstract
FROM poop
ORDER BY award
WHERE abstract LIKE discov%
LIMIT 20
它不喜欢我的where子句......任何人? (在mySQL中)
答案 0 :(得分:2)
您缺少围绕您的条件的单引号,您只是在寻找带有“discov” start 的单词,您的order by子句位于错误的位置,并且您正在使用计数( )没有其他非聚合字段分组的表达式。为了解决此问题并查找包含“discov”的单词,请使用:
SELECT title, abstract, count(award),
FROM table
WHERE abstract
LIKE '%discov%'
GROUP BY title, abstract
ORDER BY count(award)
LIMIT 20
如果你真的只想找到以“discov”开头的单词,那就用这个:
SELECT title, abstract, count(award),
FROM table
WHERE abstract
LIKE 'discov%'
GROUP BY title, abstract
ORDER BY count(award)
LIMIT 20
答案 1 :(得分:1)
此查询假定每个pi有不同的奖励。
SELECT COUNT(distinct award), pi
FROM [tablename]
GROUP BY pi
ORDER BY COUNT(distinct award) DESC
奖励数量最多的国家。
SELECT TOP 20 COUNT(distinct award), state
FROM [tablename]
GROUP BY state
ORDER BY COUNT(distinct award)
如果您不使用T-SQL,请删除TOP 20.
答案 2 :(得分:1)
在discov周围丢失''并且ORDER BY
和WHERE
被反转:
SELECT title, count(award) AS count_award, abstract
FROM table
WHERE abstract LIKE 'discov%'
GROUP BY title, abstract
ORDER BY count_award DESC
LIMIT 20