mysql - How to write a sql query -


i have 3 tables

quality

id    name ----------  1    bold  2    frank  3    quite  4    friendly 

student

id name ---------  1   2  b  3  c 

studentquality

id  fk_qual  fk_stud  1   1        1  2   2        1  3   1        2  4   2        2  5   3        2  6   1        3  7   2        3  8   3        3  9   4        3 

these tables. how students bold, frank , quite. if use in operation, 3 students, need 2 students if use bold, frank, should 3 students if use bold, frank, quite , friendly, should 1 students how query this.

you like:

  1. declaring table variable, holding values you're searching for
  2. selecting data , using table variable condition inner join , counting values of table variable , compare them amount of qualities

like:

declare  @qualities table(qname  varchar(100)); insert   @qualities           values ('bold'),('frank'),('quite');         select s.name          student s    inner join studentquality sq            on s.id = sq.fk_stud    inner join quality q            on sq.fk_qual = q.id           , q.name in (select qname @qualities)                 group s.name       having count(*) = (select count(qname) @qualities)   

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -