Jump to content

Charts with count


gmc1103

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Jacques1
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.