我正在尝试制定下面列出的查询;
Select SUM(IF (faultdistribution='crs', 1,0)*8 OR
IF (faultdistribution='configuration', 1,0)* 6 OR
IF (faulttype='business' AND faultseverity='fatal', 1,0)* 4 OR
IF (faulttype='business' AND faultseverity='major', 1,0)* 2 OR
IF (faulttype='business' AND faultseverity='moderate', 1,0)* 5 OR
IF (faulttype='business' AND faultseverity='minor', 1,0)* 3 OR
IF (faulttype='look & feel' AND faultseverity='fatal', 1,0)* 2 OR
IF (faulttype='look & feel' AND faultseverity='major', 1,0)* 1) as mysum
FROM tbl_fault WHERE product='DAS' AND faultdistribution='missed'
我打算做的是添加全部或任何一个或两个真实的IF条件。另请访问http://www.sqlfiddle.com/#!2/d2aac/44。需要帮助!
此致
答案 0 :(得分:2)
Select SUM(IF (faultdistribution='crs', 1,0)*8 +
IF (faultdistribution='configuration', 1,0)* 6 +
IF (faulttype='business' AND faultseverity='fatal', 1,0)* 4 +
IF (faulttype='business' AND faultseverity='major', 1,0)* 2 +
IF (faulttype='business' AND faultseverity='moderate', 1,0)* 5 +
IF (faulttype='business' AND faultseverity='minor', 1,0)* 3 +
IF (faulttype='look & feel' AND faultseverity='fatal', 1,0)* 2 +
IF (faulttype='look & feel' AND faultseverity='major', 1,0)* 1) as mysum
FROM tbl_fault
WHERE product='DAS'
AND faultdistribution='missed'