一个表A:id hy leftn rightn
1 101 0 102
2 102 103 0
3 103 113 112查询leftn,匹配hy,如果hy中不存在 那么把hy中不存在的lefttn归零如上图,应该把1、3归0请问如何写改语句?
1 101 0 102
2 102 103 0
3 103 113 112查询leftn,匹配hy,如果hy中不存在 那么把hy中不存在的lefttn归零如上图,应该把1、3归0请问如何写改语句?
insert into a
select 1,101,0,102 union all
select 2,102,103,0 union all
select 3,103,113,112 update A
set leftn=case when exists(select 1 from A T where T.hy=A.leftn) then leftn else 0 endselect * from a
/*
id hy leftn rightn
----------- ----------- ----------- -----------
1 101 0 102
2 102 103 0
3 103 0 112
*/
drop table a
表中有6万多条数据哦~怎么办?
-----------------------------------
有關係嗎?
select 2,102,103,0 union all
select 3,103,113,112 这个怎么回事呢?
不是很明白
select 2,102,103,0 union all
select 3,103,113,112 这个怎么回事呢?
不是很明白
---------------------------不是吧.不知说什么好啊
update A
set leftn=case when exists(select 1 from A T where T.hy=A.leftn) then leftn else 0 end
set rightnumber=case when exists(select 1 from hyclub T where T.hynumber=hyclub.rightnumber) then rightnumber else 0 end出现一下错误:将 nvarchar 值 'wh888' 转换为数据类型为 int 的列时发生语法错误。
set rightnumber=case when exists(select 1 from hyclub T where ltrim(T.hynumber)=ltrim(hyclub.rightnumber)) then rightnumber else 0 end
insert into a select 1,101,0,102 union all
select 2,102,103,0 union all
select 3,103,113,112
这是插入记录的语句相当于insert into a values(1,101,0,102)
insert into a values(2,10,103,0)