2016-11-03 74 views
0
update tbl_addemployee set 
amount_due=amount_due+((tsalary/30)*187), 
com_salary_date='2016-11-04' 
where (forUser='sun4269' and E_id) 

我想爲每個不同的記錄,其中forUser =「sun4269」 以及所述不同列名是E_ID計算表的第2列和基於表列

更新com_salary_date的不同值更新所述第三列
+0

那麼是什麼問題?向我們展示樣本數據和預期產出? –

回答

0

您需要使用INNER JOIN加入匹配的不同記錄

UPDATE 
    T 
SET 
    T.amount_due = amount_due+((tsalary/30)*187), 
    T.com_salary_date = '2016-11-04' 
FROM 
    tbl_addemployee AS T 
    INNER JOIN 
    (
     SELECT DISTINCT 
      forUser, 
      E_id 
     FROM 
      tbl_addemployee 
    ) AS X 
    ON X.forUser=T.forUser AND X.E_id=T.E_id