• 主页
• 基础类
• 应用实例
• 新技术前沿

# 求一SQL语句 实现比较没有思路

haoyuzhou009 2007-12-17 07:18:04

(M,N)内数据有可能因为删改出现不存在情况 输入的X也存在不存在的情况

...全文
109 点赞 收藏 19

19 条回复

you_tube 2007-12-20

http://blog.csdn.net/roy_88/archive/2007/02/13/1509413.aspx

falaly 2007-12-19
union 一下

haoyuzhou009 2007-12-18

haoyuzhou009 2007-12-18
TO'''fcuandy(人, 无完人;学, 无止境)

----------------- ----------------- -----------------
----------------- ----------------- -----------------

//正常情况

//取该记录到最末行

fcuandy 2007-12-18

haoyuzhou009 2007-12-18
TO'''fcuandy(人, 无完人;学, 无止境)

----------------- ----------------- -----------------
----------------- ----------------- -----------------

haoyuzhou009 2007-12-18

SQL得到的效果:1-100

SQL得到的结果是 1,3-103

-----------------

----------------- ----------------- -----------------
----------------- ----------------- -----------------

----------------- ----------------- -----------------

----------------------

----------------- ----------------- -----------------
----------------- ----------------- -----------------

fcuandy 2007-12-18

haoyuzhou009 2007-12-18
TO ''victorcai2006

－－－－－－－－－－－－－
？？？？没有看懂～～～

－－－－－－－－－－－－－ －－－－－－－－－－－－－

haoyuzhou009 2007-12-18

TO'''fcuandy(人, 无完人;学, 无止境)

-------------------------------------------------------

haoyuzhou009 2007-12-18
up

victorcai2006 2007-12-17

－－－－－－－－－－－－－
？？？？没有看懂～～～

fcuandy 2007-12-17

``````declare @x int,@m int,@n int
select @x=1,@m=3,@n=103
select *,pri=case when @x between @m and @n then 0 else case when @x<@m then -1 else 1 end end from tb where id=@x
union
select *,pri=0 from tb where id between @m and @n
order by pri,id``````

``select * from tb where id between @m and @n or id=@x order by case when id between @m and @n then 0 else case when id<@m then -1 else 1 end end ,id``

dobear_0922 2007-12-17

----------------------

dobear_0922 2007-12-17

SQL得到的效果:1-100

SQL得到的结果是 1,3-103

-----------------

haoyuzhou009 2007-12-17

haoyuzhou009 2007-12-17

SQL得到的效果:1-100

SQL得到的结果是 1,3-103

liangCK 2007-12-17

dobear_0922 2007-12-17

MS-SQL Server

3.2w+

MS-SQL Server相关内容讨论专区