日期:2014-05-18 浏览次数:20774 次
select *
from (
select *
,row_id = row_number() over (order by (case
when DialogueTime is null then ComeTimeC
else DialogueTime
end) desc)
from (
select *
from (
select *
from Orders
where Projectid=16
) a
full join
(
select *
from PatientCome
where RealProjectID=16
) b
on a.GUID = b.ComeGUID
) c
) d
where d.row_id > 18 * (4 - 1)
and d.row_id <= 18 * 4
------解决方案--------------------
如果程序是经常要用这条SQL语句,觉得放在存储过程好,从你的 d.row_id >18 * (4 - 1)格式看,应该调用时是条件是变化的吧,这样放在存储过程可减少每次SQL语句的编译。
效率的话要看你表里的数据量了的实际运行情况,数据量不大,你自己可以接受就好了
------解决方案--------------------
效率问题不大,但是我还是建议用存储过程。