当不使用select top 100 pecent...的时候,直接order by 会报错:com.microsoft.sqlserver.jdbc.SQLServerException: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.但这样的语句直接在sql的查询分析器里就没问题。
declare @t table(id int,name varchar(10)) insert into @t select 5,'asdf' insert into @t select 3,'ww' insert into @t select 7,'ss' insert into @t select 2,'dd' insert into @t select 8,'fff'select * from (select * from @t order by id)a --以上语句会报错:错误信息很明显。。 --服务器: 消息 1033,级别 15,状态 1,行 9 --除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。 select * from (select top 100 percent * from @t order by id)a --ok
我的sql是这样的:select * from a,b where a.a1>0 and (select count(*) from b where b.b1=a.a1) > 0 order by a.a3问题是如果加上top,hibernate不认啊
declare @t table(id int,name varchar(10))
insert into @t select 5,'asdf'
insert into @t select 3,'ww'
insert into @t select 7,'ss'
insert into @t select 2,'dd'
insert into @t select 8,'fff'select * from
(select * from @t order by id)a
--以上语句会报错:错误信息很明显。。
--服务器: 消息 1033,级别 15,状态 1,行 9
--除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
select * from
(select top 100 percent * from @t order by id)a
--ok
在子查询里面用了order by 后,一定要加上top