Mysql query question
How to count as 1 if is 1,2 or 5 for example
field1 = 1
field2= 1
field3= 5
field4= 2
field5=0;
field6=6;
What I need is to check if any of these fields is 1, 2 or 5 and count them as 1 and ignore the rest.
SELECT field1+field2+field3+field4+field5+field6; FROM table WHERE id=1;
// should return 4 (1+1+1+1+0+0)
Could this be done or am I going to have to do it with php?
You can use a searched
CASEstatement but as been suggested by @eggyal, there might be a design flaw in your schema. Fixing that could very well simplify your requirement.