gmc1103 Posted June 23, 2016 Share Posted June 23, 2016 Hi I have a table with differents values in some cases but all of them regarding to other table, is a relational table I need to get how many are repeated etc of each one This is my table escola dominio XXXXX 1.2 - Motivação e Empenho XXXXX 1.5 - Parcerias/Protocolos/Projetos XXXXX 2.3 Gestão dos recursos materiais e financeiros XXXXX 1.2 - Motivação e Empenho XXXXX 1.4 - Relações / Formas de Comunicação XXXXX 2.1 - Infraestruturas XXXXX 2.3 Gestão dos recursos materiais e financeiros XXXXX 2.5 Escola para todos YYYY 1.1 - Visão Estratégica / Coerência YYYY 1.4 - Relações / Formas de Comunicação YYYY 2.1 - Infraestruturas YYYY 2.3 Gestão dos recursos materiais e financeiros YYYY 2.4 Conceção, planeamento e desenvolvimento da ati YYYY 1.2 - Motivação e Empenho YYYY 1.4 - Relações / Formas de Comunicação YYYY 2.1 - Infraestruturas YYYY 2.3 Gestão dos recursos materiais e financeiros YYYY 2.5 Escola para todos ZZZZZ 1.2 - Motivação e Empenho ZZZZZ 1.4 - Relações / Formas de Comunicação ZZZZZ 2.1 - Infraestruturas ZZZZZ 2.3 Gestão dos recursos materiais e financeiros ZZZZZ 2.5 Escola para todos This is my query but not what i'm expeting SELECT DISTINCT `escola`.`escola`, `dominios`.`dominio` , COUNT(`dominios`.`dominio`) AS dominios FROM `estatistica_atividades` INNER JOIN `dominios` ON (`estatistica_atividades`.`id_dominios` = `dominios`.`id_dominio`) INNER JOIN `escola` ON (`estatistica_atividades`.`id_escola` = `escola`.`id_escola`) GROUP BY `escola`.`escola` Any help? Quote Link to comment https://forums.phpfreaks.com/topic/301384-charts-with-count/ Share on other sites More sharing options...
Barand Posted June 23, 2016 Share Posted June 23, 2016 This is my query but not what i'm expeting Telling us what you don't want isn't helpful, we need to know what you are expecting. Quote Link to comment https://forums.phpfreaks.com/topic/301384-charts-with-count/#findComment-1533968 Share on other sites More sharing options...
gmc1103 Posted June 23, 2016 Author Share Posted June 23, 2016 Hi Barand I expect to have for instance for escola field xxxx , i have 2 domain 1.1, 3 domain 2.1, etc for escola field yyyy, i have 3 domains 2.3, 4 domains 3.1...etc So, for each school and want to know and count the domains used Thanks Quote Link to comment https://forums.phpfreaks.com/topic/301384-charts-with-count/#findComment-1533979 Share on other sites More sharing options...
Jacques1 Posted June 23, 2016 Share Posted June 23, 2016 (edited) Your example numbers don't seem to match your actual data, but if you want to count the school/domain combinations, you need to group by both the school and the domain: SELECT escola.escola, dominios.dominio, COUNT(*) AS the_count FROM estatistica_atividades JOIN escola ON estatistica_atividades.id_escola = escola.id_escola JOIN dominios ON estatistica_atividades.id_dominios = dominios.id_dominio GROUP BY escola.escola, dominios.dominio ; (You really need to get rid of all those useless backticks) Edited June 23, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301384-charts-with-count/#findComment-1533984 Share on other sites More sharing options...
gmc1103 Posted July 5, 2016 Author Share Posted July 5, 2016 Hi Jacques Thanks, about the backticks is the MYsql GUI (Sqlyog) Let me see if i can explain what i need , your query seems to be ok, i will test it later 1º A teacher schedule an activity 2º The activity have domains (students, parents, teachers, etc) Then in the end of school year i must have a chart with all the domains used by school Thanks Quote Link to comment https://forums.phpfreaks.com/topic/301384-charts-with-count/#findComment-1534239 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.