Reputation: 55
My Sql Table Like this. Retrieve data from table and Count Particular data from this values.If given no is 6 means the count is 4.
+---------+-------------+-------------+
| id | Values |
+---------+-------------+-------------+
| 11 | 1,2,4,5,6 |
| 12 | 1,2,6 |
| 13 | 4,5,6 |
| 14 | 2,3,6 |
+---------+------------+--------------+
Upvotes: 2
Views: 851
Reputation: 64476
You can use find_in_set
to search the value from comma separated string
select count(*) total
from demo
where find_in_set(6, `Values`) > 0;
Upvotes: 5