1

I want to multiply 4 with number of faults if faulttype='business' and faultseverity='fatal', using query listed below;

Select faulttype, IF (faulttype='business' AND faultseverity='fatal', 1,0)* 4 FROM tbl_fault WHERE product='DAS' AND faultdistribution='missed'
 group by faulttype

I am getting result business instead of numeric value, What should be corrected in this query?

Regards

5
  • Which column of your result set are you trying to retrieve? The first is still faulttype, the second will be the numeric value. Commented Oct 8, 2013 at 6:09
  • I want to retrieve the numeric value from 2nd column. Commented Oct 8, 2013 at 6:11
  • 1
    Yes, but you should show us the code, not the query. The problem must be there. Commented Oct 8, 2013 at 6:13
  • $cmsc= mysql_query("Select faulttype, IF (faulttype='business' AND faultseverity='fatal', 1,0)* 4 FROM tbl_fault WHERE product='DAS' AND faultdistribution='missed' group by faulttype"); while ($cresult = mysql_fetch_array ($cmsc)) $fat[0] = $cresult[0]; Commented Oct 8, 2013 at 6:13
  • 4
    $cresult[0]: the first index is the first column. Use $cresult[1] for the second column. Commented Oct 8, 2013 at 6:15

2 Answers 2

2

try this

Select faulttype, sum(IF (faulttype='business' AND faultseverity='fatal', 1,0))*4 FROM tbl_fault WHERE product='DAS' AND faultdistribution='missed'
 group by faulttype;

For reference see the sql fiddle.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this

Select CASE faulttype WHEN faulttype='business' AND faultseverity='fatal' THEN 1*4 ELSE 0 END AS rez FROM tbl_fault WHERE product='DAS' AND faultdistribution='missed'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.