我有一个主表,命名为我在一个月内每天table1
存储或更新数据的地方。mobileNo
;WITH table1 AS (SELECT * FROM (VALUES
(9999999999, '01/10/2013', NULL, NULL, NULL, NULL),
(9999999999, NULL, '02/10/2013', NULL, NULL, NULL),
(9999999999, NULL, NULL, '03/10/2013', NULL, NULL),
(9999999999, NULL, NULL, NULL, '04/10/2013', NULL),
(9999999999, NULL, NULL, NULL, NULL, '30/10/2013'),
(9999999999, NULL, NULL, NULL, NULL, NULL),
(8888888888, '01/10/2013', NULL, NULL, NULL, NULL),
(8888888888, NULL, '02/10/2013', NULL, NULL, NULL),
(8888888888, NULL, NULL, '03/10/2013', NULL, NULL),
(8888888888, NULL, NULL, NULL, '04/10/2013', NULL),
(8888888888, NULL, NULL, NULL, NULL, '30/10/2013'))
as t(mobileno,date1,date2,date3,date4,date30))
我还有另一个名为table1的表table2
,我在其中保持唯一。mobileNo
现在我想更新是否存在任何数据table2
。table1
table1
mobileno date1 date2 date3 date4 date30
--------------- ---------- ---------- ---------- ---------- ----------
8888888888 01/10/2013 02/10/2013 03/10/2013 04/10/2013 30/10/2013
9999999999 01/10/2013 02/10/2013 03/10/2013 04/10/2013 30/10/2013
但是我尝试了这样的查询
UPDATE table1
set table1.date1 =
(SELECT date1 from table2 where table2.mobileno = table1.mobileno)
Where table2.mobileno = table1.mobileno
如何在单个查询中更新而不重复更新 30 个。日期列,请帮助我。提前致谢。