----先更新 update b set num = num + 1 from tableB as b inner join table A as a on b.NO = a.NO----再插入 insert into tableB select a.* from tableA as a left join tableB as b on a.NO = b.NO where b.NO is null
----先更新 update b set num = num + 1 from tableB as b inner join ( select no from tableA group by no ) as a on b.NO = a.NO----再插入 insert into tableB(no,num) select no,1 from ( select no from tableA group by no ) as a left join tableB as b on a.NO = b.NO where b.NO is null
num-->qty----先更新 update b set qty = b.qty + 1 from tableB as b inner join ( select no from tableA group by no ) as a on b.NO = a.NO----再插入 insert into tableB(no,qty) select a.no,1 from ( select no from tableA group by no ) as a left join tableB as b on a.NO = b.NO where b.NO is null
希望能看到舉例來避免理解錯了意思,你下面的解釋還是和上面一樣的。還是猜一下你的需求吧。try --先update,再insert--Update Update B Set qty = qty + 1 From A Inner Join B On A.no = B.no--Insert Insert B Select distinct no,... From A
--先插 insert into tableB select distinct a.* from tableA as a left join tableB as b on a.NO = b.NO where b.NO is null -- 再update update tableB A set A.Qty = (select sum(B.Qty) from tableB B where B.no = A.no) --再讀 select distinct * from tableB
update b set num = num + 1
from tableB as b
inner join table A as a on b.NO = a.NO----再插入
insert into tableB
select a.* from tableA as a
left join tableB as b on a.NO = b.NO
where b.NO is null
ok?
update b set num = num + 1
from tableB as b
inner join (
select no from tableA group by no ) as a on b.NO = a.NO----再插入
insert into tableB(no,num)
select no,1 from (
select no from tableA group by no ) as a
left join tableB as b on a.NO = b.NO
where b.NO is null
update b set qty = b.qty + 1
from tableB as b
inner join (
select no from tableA group by no ) as a on b.NO = a.NO----再插入
insert into tableB(no,qty)
select a.no,1 from (
select no from tableA group by no ) as a
left join tableB as b on a.NO = b.NO
where b.NO is null
--先update,再insert--Update
Update B Set qty = qty + 1 From A Inner Join B On A.no = B.no--Insert
Insert B Select distinct no,... From A
看看樓主的選擇吧。
insert into tableB
select distinct a.* from tableA as a
left join tableB as b on a.NO = b.NO
where b.NO is null
-- 再update
update tableB A set A.Qty = (select sum(B.Qty) from tableB B where B.no = A.no)
--再讀
select distinct * from tableB
以前问题放几天都没人理。
我国有希望了。