同一个表中两个属性列合并的问题 select id , case when parentID = 0 then typeid else parentID end from tb 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table tb(ID int, TypeID int, ParentID int)insert into tb values(1 , 3 , 0)insert into tb values(2 , 3 , 0)insert into tb values(3 , 3 , 0)insert into tb values(4 , 3 , 0)insert into tb values(5 , 3 , 0)insert into tb values(6 , 3 , 0)insert into tb values(7 , 10 , 0)insert into tb values(8 , 11 , 0)insert into tb values(9 , 11 , 0)insert into tb values(10 , 13 , 3)insert into tb values(11 , 14 , 3)insert into tb values(12 , 15 , 5)insert into tb values(13 , 16 , 5)insert into tb values(14 , 4 , 0)insert into tb values(15 , 18 , 5)insert into tb values(16 , 19 , 5)insert into tb values(17 , 20 , 5)insert into tb values(18 , 21 , 6)insert into tb values(19 , 22 , 6)insert into tb values(20 , 23 , 6)insert into tb values(21 , 23 , 6)insert into tb values(22 , 32 , 0)insert into tb values(23 , 28 , 9)insert into tb values(24 , 30 , 0)insert into tb values(25 , 3 , 0)insert into tb values(26 , 4 , 0)insert into tb values(27 , 3 , 0)insert into tb values(28 , 3 , 0)insert into tb values(29 , 3 , 0)insert into tb values(30 , 4 , 0)insert into tb values(31 , 10 , 0)insert into tb values(32 , 30 , 0)goselect id , case when parentID = 0 then typeid else parentID end aid from tbdrop table tb/*id aid ----------- ----------- 1 32 33 34 35 36 37 108 119 1110 311 312 513 514 415 516 517 518 619 620 621 622 3223 924 3025 326 427 328 329 330 431 1032 30(所影响的行数为 32 行)*/ declare @t table(ID int, TypeID int, ParentID int)insert @t select 1,3,0insert @t select 2,3,0insert @t select 3,3,0insert @t select 4,3,0insert @t select 5,3,0insert @t select 6,3,0insert @t select 7,10,0insert @t select 8,11,0insert @t select 9,11,0insert @t select 10,13,3insert @t select 11,14,3insert @t select 12,15,5insert @t select 13,16,5insert @t select 14,4,0insert @t select 15,18,5insert @t select 16,19,5insert @t select 17,20,5insert @t select 18,21,6insert @t select 19,22,6insert @t select 20,23,6insert @t select 21,23,6insert @t select 22,32,0insert @t select 23,28,9insert @t select 24,30,0insert @t select 25,3,0insert @t select 26,4,0insert @t select 27,3,0insert @t select 28,3,0insert @t select 29,3,0insert @t select 30,4,0insert @t select 31,10,0insert @t select 32,30,0select id,case when parentID<>0 then parentID else TypeID end Aid from @tid Aid----------- -----------1 32 33 34 35 36 37 108 119 1110 311 312 513 514 415 516 517 518 619 620 621 622 3223 924 3025 326 427 328 329 330 431 1032 30(32 行受影响) select id, case arentID then TypeID else ParentID end as aIDfrom tb select id, aid=(case when ParentID=0 then TypeID else ParentID end) from tb 触发器的优劣 怎么修改普通列 变成自动增长 sql2000与sql2005 求优化SQL语句!!!!!!!!-------------- 请教一个sql语句的写法 完整备份数据库文件很大,恢复速度很慢怎么解决? sql97中触发器怎样显示自订的信息给用户,且程式可继续往下执行 asp语句问题 如何用游标读表中的记录???? 替换表中的字段中的数字 update语句怎么写?急,在线等 请教sql server中identity标识列的问题 所有分只为求一条SQL语句,急求
insert into tb values(1 , 3 , 0)
insert into tb values(2 , 3 , 0)
insert into tb values(3 , 3 , 0)
insert into tb values(4 , 3 , 0)
insert into tb values(5 , 3 , 0)
insert into tb values(6 , 3 , 0)
insert into tb values(7 , 10 , 0)
insert into tb values(8 , 11 , 0)
insert into tb values(9 , 11 , 0)
insert into tb values(10 , 13 , 3)
insert into tb values(11 , 14 , 3)
insert into tb values(12 , 15 , 5)
insert into tb values(13 , 16 , 5)
insert into tb values(14 , 4 , 0)
insert into tb values(15 , 18 , 5)
insert into tb values(16 , 19 , 5)
insert into tb values(17 , 20 , 5)
insert into tb values(18 , 21 , 6)
insert into tb values(19 , 22 , 6)
insert into tb values(20 , 23 , 6)
insert into tb values(21 , 23 , 6)
insert into tb values(22 , 32 , 0)
insert into tb values(23 , 28 , 9)
insert into tb values(24 , 30 , 0)
insert into tb values(25 , 3 , 0)
insert into tb values(26 , 4 , 0)
insert into tb values(27 , 3 , 0)
insert into tb values(28 , 3 , 0)
insert into tb values(29 , 3 , 0)
insert into tb values(30 , 4 , 0)
insert into tb values(31 , 10 , 0)
insert into tb values(32 , 30 , 0)
goselect id , case when parentID = 0 then typeid else parentID end aid from tbdrop table tb
/*
id aid
----------- -----------
1 3
2 3
3 3
4 3
5 3
6 3
7 10
8 11
9 11
10 3
11 3
12 5
13 5
14 4
15 5
16 5
17 5
18 6
19 6
20 6
21 6
22 32
23 9
24 30
25 3
26 4
27 3
28 3
29 3
30 4
31 10
32 30(所影响的行数为 32 行)*/
insert @t select 1,3,0
insert @t select 2,3,0
insert @t select 3,3,0
insert @t select 4,3,0
insert @t select 5,3,0
insert @t select 6,3,0
insert @t select 7,10,0
insert @t select 8,11,0
insert @t select 9,11,0
insert @t select 10,13,3
insert @t select 11,14,3
insert @t select 12,15,5
insert @t select 13,16,5
insert @t select 14,4,0
insert @t select 15,18,5
insert @t select 16,19,5
insert @t select 17,20,5
insert @t select 18,21,6
insert @t select 19,22,6
insert @t select 20,23,6
insert @t select 21,23,6
insert @t select 22,32,0
insert @t select 23,28,9
insert @t select 24,30,0
insert @t select 25,3,0
insert @t select 26,4,0
insert @t select 27,3,0
insert @t select 28,3,0
insert @t select 29,3,0
insert @t select 30,4,0
insert @t select 31,10,0
insert @t select 32,30,0
select id,case when parentID<>0 then parentID else TypeID end Aid from @t
id Aid
----------- -----------
1 3
2 3
3 3
4 3
5 3
6 3
7 10
8 11
9 11
10 3
11 3
12 5
13 5
14 4
15 5
16 5
17 5
18 6
19 6
20 6
21 6
22 32
23 9
24 30
25 3
26 4
27 3
28 3
29 3
30 4
31 10
32 30(32 行受影响)
id,
case arentID then TypeID else ParentID end as aID
from tb