field1 | field2 | field3 | field4 | field5 | field6 | field7 | field8 | field9 | field10 | field11 | id |
---|---|---|---|---|---|---|---|---|---|---|---|
N | N | N | Y | Y | N | N | N | N | N | N | 5343 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 |
N | N | N | N | N | N | N | N | N | N | N | 5361 |
N | N | N | N | N | N | N | N | N | N | N | 5361 |
N | N | N | N | N | N | N | N | N | N | N | 5361 |
N | N | N | N | N | N | N | N | N | N | N | 5361 |
N | N | N | N | N | N | N | N | N | N | N | 5362 |
N | N | N | N | N | N | N | N | N | N | N | 5362 |
N | N | N | N | N | N | N | N | N | N | N | 5362 |
N | N | N | N | N | N | N | N | N | N | N | 5362 |
N | N | N | N | N | N | N | N | N | N | N | 9475 |
N | N | N | N | N | N | N | N | N | N | N | 9475 |
N | N | N | N | N | N | N | N | N | N | N | 9475 |
N | N | N | N | N | N | N | N | N | N | N | 9476 |
N | Y | N | N | N | N | N | Y | Y | N | N | 9476 |
N | Y | N | N | N | N | N | Y | Y | N | N | 9476 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 |
N | N | N | N | N | N | N | N | N | N | N | 5369 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 |
I have above table and I want to find out how many "Y" are present in each row. In the above table each column contains two values only. That is "Y" OR "N".
Answere:
SELECT field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,id, IF(field1= 'Y',1,0) + IF(field2= 'Y',1,0) +IF(field3= 'Y',1,0) + IF(field4= 'Y',1,0) +IF(field5= 'Y',1,0) + IF(field6= 'Y',1,0) +IF(field7= 'Y',1,0) + IF(field8= 'Y',1,0) +IF(field9= 'Y',1,0) + IF(field10= 'Y',1,0) +IF(field11= 'Y',1,0) as testcolumn,LENGTH(REPLACE(CONCAT( field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11),'N','')) as len FROM member_stats LIMIT 50;
field1 | field2 | field3 | field4 | field5 | field6 | field7 | field8 | field9 | field10 | field11 | id | testcolumn | len |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N | N | N | Y | Y | N | N | N | N | N | N | 5343 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5343 | 2 | 2 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5357 | 1 | 1 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5358 | 3 | 3 |
N | N | N | N | N | N | N | N | N | N | N | 5361 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5361 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5361 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5361 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5362 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5362 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5362 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 5362 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 9475 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 9475 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 9475 | 0 | 0 |
N | N | N | N | N | N | N | N | N | N | N | 9476 | 0 | 0 |
N | Y | N | N | N | N | N | Y | Y | N | N | 9476 | 3 | 3 |
N | Y | N | N | N | N | N | Y | Y | N | N | 9476 | 3 | 3 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 | 2 | 2 |
N | N | N | Y | Y | N | N | N | N | N | N | 5366 | 2 | 2 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 | 1 | 1 |
N | N | N | N | Y | N | N | N | N | N | N | 5367 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | Y | N | N | N | N | 5369 | 1 | 1 |
N | N | N | N | N | N | N | N | N | N | N | 5369 | 0 | 0 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 | 3 | 3 |
N | N | Y | Y | Y | N | N | N | N | N | N | 5370 | 3 | 3 |
0 comments:
Post a Comment