1

我正在尝试制定下面列出的查询;

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。需要帮忙!

问候

4

1 回答 1

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'
于 2013-10-08T09:46:33.917 回答