Your database is poorly designed and you are going to have a lot of trouble down the line.
Using the current structure you can get the count using the find_in_set
function but that you should avoid .
Your table is as
create table test
(jobid int ,city varchar(100));
insert into test values
(1,'New York'),
(2,'New York, Ohio,Virginia'),
(3,'New York,Virginia');
Now to get the count you can use the following
select
count(*) as tot from test
where
find_in_set('Virginia',city) > 0;
As I mentioned this is a poor db design the ideal would be as
- first a job table with job details
- a location table containing all the locations
- and finally a table linking a job and a location
So it would look like
create table jobs (jobid int, name varchar(100));
insert into jobs values
(1,'PHP'),(2,'Mysql'),(3,'Oracle');
create table locations (id int, name varchar(100));
insert into locations values (1,'New York'),(2,'Ohio'),(3,'Virginia');
create table job_locations (id int, jobid int, location_id int);
insert into job_locations values
(1,1,1),(2,2,1),(3,2,2),(4,2,3),(5,3,1),(6,3,3);
Now getting the count and many more operations will be fairly easy
select
count(j.jobid) as tot
from jobs j
join job_locations jl on jl.jobid = j.jobid
join locations l on l.id = jl.location_id
where
l.name = 'Virginia'
For counting all the jobs per city and using the above schema it would very simple
select
l.name,
count(j.jobid) as tot
from jobs j
join job_locations jl on jl.jobid = j.jobid
join locations l on l.id = jl.location_id
group by l.name
DEMO