gpt4 book ai didi

mysql - 这个sql查询在mysql中有效,但在mssql中无效

转载 作者:行者123 更新时间:2023-11-29 12:04:41 25 4
gpt4 key购买 nike

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 中我收到错误:

Column 'songs2.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

++++++++++++++++++++现在我用这个查询选择:选择艺术家、专辑、歌曲(从歌曲顺序中选择前 1000 首 * 按年份 asc、艺术家 asc)作为歌曲 2,其中艺术家喜欢 'a%' 按艺术家、专辑、歌曲分组;但它不按艺术家分组,我希望查询中每首歌曲只有一位艺术家

最佳答案

在 mysql 中,您可以选择 group by 语句中没有的值。这在 mssql 中是不可能的。

SELECT artist FROM 
(
select * from songs
) as songs2
where artist like 'a%' group by artist;

而且您也不能在子查询中使用 order by。

关于mysql - 这个sql查询在mysql中有效,但在mssql中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31718692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com