【发布时间】:2015-10-21 12:15:37
【问题描述】:
mysql:
SELECT *
FROM (select * from songs order by artist asc) as songs2
WHERE artist LIKE 'a%' GROUP BY artist`
mssql:
SELECT *
FROM (select top 1000 * from songs order by artist asc) as songs2
WHERE artist LIKE 'a%' GROUP BY artist
这在 mysql 中有效,但在 mssql 中我得到一个错误:
列 'songs2.id' 在选择列表中无效,因为它不是 包含在聚合函数或 GROUP BY 子句中
++++++++++++++++++++ 现在我用这个查询选择: SELECT artist,album,song from (select top 1000 * from song order by year asc, artist asc) as song2 where artist like 'a%' group by artist,album,song; 但它不按艺术家分组,我希望查询中每首歌曲只有一位艺术家
【问题讨论】:
-
按照错误消息中的说明执行操作并删除该子句。它实际上并没有做任何事情(不能保证外部查询尊重该顺序,即使它可能会这样做)。
-
我把sql改成
标签: mysql sql-server