select top 80 percent * from tb order by id
except
select top 20 percent * from tb order by id
谢谢 好用
问下 t 是干什么的
不用还不行
t表示子查询的别名,这个一定要加的,别名取什么就随便了, a b c d e f都可以。
我现在要求 这个SQL语句里的最大值
select MAX(data1)as maxnum from (select top 80 percent * from shuju order by id) t
except
select top 20 percent * from shuju order by id
语法没错误
但运行的时候提示
使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式
我改成
select MAX(data1)as maxnum from (select top 80 percent data1 from shuju order by id) t
except
select top 20 percent data1 from shuju order by id
结果提示
如果该语句包含 UNION、INTERSECT 或 EXCEPT 运算符,则 ORDER BY 项必须出现在选择列表中。
这个 ORDER BY 应该放在哪
select MAX(data1)as maxnum from (
select * from (select top 80 percent * from shuju order by id) t
except
select top 20 percent * from shuju order by id) tp