mysql - Using the division operator in a query that gets data from 3 tables -


i having trouble writing query gets information 3 different tables. right have query runs... not getting right result. talking peers found out 1 way query use division operator confused on how it. show query definition, tables, , query wrote , maybe here can me fix query or explain me how utilize division operator!

query definition:

find users utilize every protein in jobs.  find users have used every protein once.  within 1 job or 100 jobs. 

tables:

create table job(uid integer,job_id integer auto_increment,input varchar(500), foreign key(uid) references user(uid) on delete cascade, primary key(job_id))engine = innodb;  create table protein_info(pid integer,sequence varchar(200), foreign key(pid) references protein(pid),primary key(pid))engine = innodb;  create table protein(pid integer,name varchar(50),primary key(pid)) engine=innodb;  insert job(uid, job_id, input) values(1, 1, abc),(2, 2, bce), (1, 3, aeo),(3, 4, pqo),(1, 5, bce), (1, 6, pqo) insert protein_info(pid, sequence) values (1,abc),(2,bce)(3,aeo),(4,pqo) insert protein(pid, name) values (1,a),(2,b),(3,c),(4,d) 

so after these values inserted.... want retrieve information user id 1 because 1 used proteins. want output user id , count of jobs of user used proteins. in case user id 1.

these 2 tables join on input , sequence. join them when job.input = protein_info.sequence.

the query have tried.

select u.uid, count(j.job_id) job j  inner join protein_info p on j.input = p.sequence  group j.job_id  having count(j.job_id) = (select count(pid) protein); 

here's fiddle

you close:

select j.uid, count(j.job_id) , count(distinct j.input) protein_info p  inner join job j   on j.input = p.sequence  group j.uid  having count(distinct j.input) = (select count(pid) protein); 

what had wrong was:

  1. group needed uid.
  2. having needed count distinct j.inputs not jobs.

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -