原贴:
http://topic.csdn.net/u/20100322/10/9a0c01d4-f2bb-402d-b189-573feb93f874.html现在值为:
name 量 差值 差名
8117 3 2
8238 5 1
8206 6 1
8202 7 1
8119 7 1
8120 7 1
8218 7 1
8312 8 2
8227 10 1
8320 10 1
8128 11 2
8107 13 1
我现在想在加一列,这一列(与谁的差值),字段为:差名最终结果为:
name 量 差值 差名
8117 3 2 8238
8238 5 1 8206
8206 6 1 8202
8202 7 1 8312
8119 7 1 8312
8120 7 1 8312
8218 7 1 8312
8312 8 2 8227
8227 10 1 8218
8320 10 1 8218
8128 11 2 8107
8107 13 0 0
http://topic.csdn.net/u/20100322/10/9a0c01d4-f2bb-402d-b189-573feb93f874.html现在值为:
name 量 差值 差名
8117 3 2
8238 5 1
8206 6 1
8202 7 1
8119 7 1
8120 7 1
8218 7 1
8312 8 2
8227 10 1
8320 10 1
8128 11 2
8107 13 1
我现在想在加一列,这一列(与谁的差值),字段为:差名最终结果为:
name 量 差值 差名
8117 3 2 8238
8238 5 1 8206
8206 6 1 8202
8202 7 1 8312
8119 7 1 8312
8120 7 1 8312
8218 7 1 8312
8312 8 2 8227
8227 10 1 8218
8320 10 1 8218
8128 11 2 8107
8107 13 0 0
解决方案 »
- 一个固定大小窗体在本机运行正常,到别台运行变小~!在线等~!两小时内结贴
- COM口如何用serialport.write 发送下面这个指令 ESC [ / 1
- asp.net后台如何调用js
- 问个其他问题 魔兽争霸的回放文件为什么那么小?
- 算法高手请进
- C#调用VC的DLL。需要传入一个字符指针,怎么办,谢谢。
- 高分求救,让子窗体成为主窗体的树形菜单
- 帮帮我
- 请教:在C#编程中用SaveFileDialog类保存文件,如何另外增加字符编码(ANSI、UTF-8等)选项的Filter。
- 救命啊!升级到了IE5.5,office出现50次限制,要我注册了。
- 请教购物车数量的问题。
- C#开发word编辑器
isnull((select top 1 min(t.name) from @t t where t.num>tt.num group by t.num),tt.name)
declare @t table([name] varchar(20),num int)/*
insert into @t select '刘水',4
union all select '刘玉', 4
union all select '王难', 6
union all select '王四', 6
union all select '张三', 7
*/
insert into @t select 8101, 29
union all select 8102, 8
union all select 8103 ,19
union all select 8105 ,15
union all select 8106 ,11
union all select 8107 ,1
union all select 8108 ,8
union all select 8110 ,16
union all select 8111 ,11
union all select 8112 ,25
union all select 8113 ,19
union all select 8117 ,3
union all select 8118 ,31
union all select 8120 ,1
union all select 8124 ,16
union all select 8125 ,13
union all select 8126 ,14
union all select 8128 ,9
union all select 8130 ,14
union all select 8131 ,29
union all select 8132 ,10
union all select 8133 ,14
union all select 8141 ,23
union all select 8143 ,2
union all select 8201 ,18
union all select 8202 ,1
union all select 8203 ,20
union all select 8205 ,17
union all select 8207 ,14
union all select 8208 ,12
union all select 8210 ,11
union all select 8213 ,8
union all select 8215 ,17
union all select 8216 ,10
union all select 8217 ,20
union all select 8218 ,1
union all select 8219 ,24
union all select 8220 ,23
union all select 8223 ,18
union all select 8224 ,33
union all select 8227 ,10
union all select 8232 ,16
union all select 8234 ,13
union all select 8238 ,1
union all select 8241 ,13
union all select 8302 ,19
union all select 8303 ,13
union all select 8304 ,21
union all select 8306 ,23
union all select 8308 ,17
union all select 8310 ,14
union all select 8311 ,17
union all select 8312 ,1
union all select 8313 ,15
union all select 8314 ,17
union all select 8315 ,12
union all select 8319 ,13
union all select 8320 ,1
union all select 8324 ,18
union all select 8325 ,10
union all select 8327 ,18
union all select 8329 ,24
union all select 8330 ,9
union all select 8332 ,12
union all select 8333 ,8
union all select 8335 ,17
union all select 8343 ,17
select * from @t order by num desc select COUNT(1) from @t group by [num] select *,isnull((select top 1 min(t.num) from @t t where t.num>tt.num group by t.num )-tt.num,0) result,
isnull((select top 1 min(t.name) from @t t where t.num>tt.num group by t.num),tt.name)
from @t tt
order by num desc
isnull((select top 1 bm from @t t where t.num>tt.num ),0) result2
from @t tt