UPDATE a
SET
b = b.b,
c = b.c,
d = b.d
from [Table1] a,
(select 35 as a ,sum(b) b,sum(c) c, sum(d) d from [Table1] where c=1 and a <33) b
where a.a = b.a and a=35
貌似没有。
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
d = (select sum(d) from [Table1] where c=1 and a <33)
where a=35
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
d = (select sum(d) from [Table1] where c=1 and a <33)
where a=35
[Quote=引用 1 楼 Limpire 的回复:]
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
...
n = (select sum(n) from [Table1] where c=1 and a <33)
where a=35
[/Quote]
同意.
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
...
n = (select sum(n) from [Table1] where c=1 and a <33)
where a=35;
[Quote=引用 1 楼 Limpire 的回复:]
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
...
n = (select sum(n) from [Table1] where c=1 and a <33)
where a=35;
[/Quote]
搞定了
感谢happyflystone的启发,最终SQL:
UPDATE aa
SET
b = bb.b,
c = bb.c,
d = bb.d
from [Table1] aa,
(select sum(b) as a ,sum(b) b,sum(c) c,sum(d) d from [Table1] where c=1 and a <33) bb
where aa.a=35
[Quote=引用 6 楼 happyflystone 的回复:]
SQL codeUPDATE a
SET
b = b.b,
c = b.c,
d = b.d
from [Table1] a,
(select 35 as a ,sum(b) b,sum(c) c, sum(d) d from [Table1] where c=1 and a <33) b
where a.a = b.a and a=35
[/Quote]
列名 'a' 不明确。
[Quote=引用 5 楼 kakajya 的回复:]
貌似没有。
UPDATE [Table1] SET
b = (select sum(b) from [Table1] where c=1 and a <33),
c = (select sum(c) from [Table1] where c=1 and a <33),
d = (select sum(d) from [Table1] where c=1 and a <33)
where a=35