关于update更新表问题
有如下两个表
T1(customid(顾客帐号),ydate(年份),ysale(年消费总额))
T2(customid(顾客帐号),date(日期),sale(消费金额))
--------
T1:
customid ydate ysale
11 2004 null
11 2005 null
12 2005 null
12 2006 null
13 2005 null
---------
T2:
customid date sale
11 200409 209
11 20041209 1280
11 2005-03-19 10888
12 2005-01-23 2396
12 200507 8900
13 2005-10-24 10588
13 20051205 132
------------
统计T2表每个顾客的年消费总额,然后更新到表T1中,用sql语句如何写???
------解决方案--------------------update t1
set ysale=(select sum(sale) from t2 where customid=t1.customid and left([date],4)=t1.ydate)