mysql - Count groups in table but if any record in 2 group is same then consider it as one group only -


i woking on production database in organisation. have come across 1 scenario. here sample data generated. actual data similar only, changed field names. table structure similar this,

tableai - unsigned bigint(20) - auto increment index logindetails -  varchar(200)      logintype - tinyint(4)  (2- gmail, 3 facebook)    studentid - unsigned bigint(20)    tableai | logindetails | logintype | studentid 1 | abc@gmail.com | 2 | 333 2 | abc@facebook.com | 3 | 333 3 | xyz@facebook.com | 3 | 444 4 | xxx@gmail.com | 2 | 444 5 | test@gmail.com | 2 | 555 6 | abc@facebook.com | 3 | 555 7 | ac@facebook.com | 3 | 666 8 | ac@gmail.com | 2 | 777 9 | abc@facebook.com | 3 | 777 

i want count total number of students (that simple). here requirement if logindetail same 2 students consider them 1 student.

so, above example studentid 333, 555 , 777 have same facebook email id. so, when count number of students, have consider these 2 student ids 1 though gmail account different. so, if 1 login details same, 2 persons, want treat 2 persons 1 person only. in production data, there such data have consider 4-5 personids 1 person based on login details.

so, above sample table, need generate query returns total number of students 3. (not 5). distinct student ids (333,555,777) , 444 , 666

some query tis give output:

select   count(*), -- test  group_councat(t.studentid) stundents,  t.logindetails,  max(t.logintype) logintype,  t.studentid tableai t group t.logindetails having count(*) = 2; 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -