2013-10-08 181 views
1

我想制定一個查詢下面列出;MySQL查詢乘法,加法和除法

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

你有什麼打算呢?你的'我打算做的是添加全部或任何一個或兩個真實的IF條件。'目前尚不清楚 – AdrianBR

回答

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'