mysql - SQL query to display a matching in two tables -



mysql - SQL query to display a matching in two tables -

g k 1 2 3 4 ... k 2 2 1 1 3 ... 1 2 2 4 2 2 2 1 4 2 5 2

i have 2 tables. parent table , pupil table. need find parent or family has 2 kids in 2 different grades. table above represents number of parents have kids in multiple different grades. illustration grade k , grade 1 there 2 families have 2 kids both in k , first grade.

what need come query find families or parents have 2 kids in 2 different grades.

you can in sql, unpleasant query:

select (sum(k + `1` + `2` + . . . ) - (case when g = 'k' k when g = `1` `1` when g = `2` `2` . . . ) ) / 2 table t;

the basic thought take sum of numbers on 1 line, subtract ones along diagonal, , split 2. note might not right. families have kids in 3 grades overcounted. not have plenty info prepare this. more detailed info help.

mysql sql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -