今天遇到一个奇怪的问题,项目突然要从mysql切换到sql server数据库,包含order by 子句的嵌套子查询报错. 示例:select top 10 name,age,sex from ( select * from user order by id desc) temp; 在mysql数据库没有问题,但是sql server中报错: [Err] 42000 - [SQL Server]除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.…
执行sql语句: select * from ( select * from tab where ID>20 order by userID desc ) as a order by date desc 逻辑上看着挺对 但是报错: 除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.子查询和公用表表达式中无效. 只要我们在嵌套子查询视图里面加入: top 100 percent 即可 select * from ( select top 100 p…
SQL语句: select * from (select distinct t2.issue,cashmoney from (select distinct issue from lot_gamepara)t1 join(select distinct cashmoney,issue from lot_cash)t2on t1.issue = t2.issue order by issue,cashmoney ) tt1,(select poscode from lot_game where t…