I have the following:
SELECT field1,
field2,
field3,
IF(field4 = 'valuex', COUNT(field4), 0) AS result
FROM tablex;`
But even though I have more records that I want to show, it only tells me all of the condition and shows them in a single record.
I need to get the other records of the table and the total value of the condition, not just a COUNT result.
答案 0 :(得分:0)
You want the conditional as an argument to the SUM()
:
SELECT field1, field2, field3,
SUM( field4 = 'valuex') AS result
FROM tablex;
This uses a convenient short-cut in MySQL. A boolean is treated as a number in a numeric context, with "1" for true and "0" for false.