标签:ide span png closed end isp div .com 大于等于
现在数据如下:
需求如下:
要求 更新 Earnings 表中的Earnings字段 当 Table_2 KPI 大于等于1时 Earinings = KPI* 2000,否则等于 KPI* 1500
1 Update Earnings 2 set Earnings = ( 3 SELECT 4 CASE WHEN TABLE_2.KPI >= 1 5 THEN Table_2.KPI * 2000 6 ELSE Table_2.KPI * 1500 7 END 8 FROM Table_2 WHERE Table_2.GId = Earnings.Id)
结果如下:
注: 子查询里的结果必须唯一,否则出错; 可以根据需求 添加DISTINCT
1 Update Earnings 2 set Earnings = ( 3 SELECT DISTINCT 4 CASE WHEN TABLE_2.KPI >= 1 5 THEN Table_2.KPI * 2000 6 ELSE Table_2.KPI * 1500 7 END 8 FROM Table_2 WHERE Table_2.GId = Earnings.Id)
标签:ide span png closed end isp div .com 大于等于
原文地址:http://www.cnblogs.com/lao-tang/p/6541889.html