con.execute "update Temp_Report"&userid&" set datal = total, h = n from (select count(*) n, sum(isnull(int2,0)) total, w from Temp_Report"&userid&" group by w) as a where Temp_Report"&userid&".w = a.w"
其中不明白的地方是:
from (select count(*) n, sum(isnull(int2,0)) total //from 后边不是应该接的是从哪个表吗? 但这个后边应该表,而是列吧?另外,n , total 是将count 和 sum(isnull(int2,0))值保持到 n 和total吗?
1.首先子查询select count(*) n, sum(isnull(int2,0)) total, w from Temp_Report"&userid&" group by w 查询出来的相当于一张临时表
2.值是保持的 只要字段名字对应 所以他在子查询里面进程了 as操作 count 和sum的记过分别保存在 n 和total中 as可以省略 这么写你应该能容易理解些 elect count(*) as n, sum(isnull(int2,0)) as total, w from Temp_Report"&userid&" group by w
select count(*) n, sum(isnull(int2,0)) total, w from Temp_Report"&userid&" group by w
这是一个表, 从 emp_Report"&userid&" 中查出 n,total,w作为表的三个字段