Sum a column by Mysql ranges

Asked

Viewed 35 times

0

Personal I have a table in my Mysql database like this:

Table name is tb_cargaHora

I’m trying something like this:

SELECT nome, matricula, SUM(carga_hora) FROM tb_cargaHora Order BY nome;

but only the result of Andre.

id name registration discip hour
2 Andre 191131 INF03 60
3 Andre 191131 TEC01 60
4 Julia 203331 CCI02 20
5 Julia 203331 TEC01 60

I would like to add only the workload of students leaving so;

name license plate hour
Andre 191131 120
Julia 203331 80
  • 1

    Search for GROUP BY

  • as @Woss pointed, you need to group, see this question: https://answall.com/a/320494/57220 or here https://answall.com/a/228296/57220

1 answer

-2


As each student has a single enrollment, Cvoce can group the data by enrollment, so in your result will have the number of lines equal to the number of right enrollments, ie a line for each student.

SELECT nome, matricula, SUM(carga_hora) FROM tb_cargaHora GROUP BY matricula Order BY nome;
  • It worked really well thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.