show summation of mysql columns and their columns

1

I've been googling and I do not quite understand how to show the sum of a column and show the values of the columns I add.

for example:

Table Users id, first name, value1 value2

I would like to show the sum of the values 1 but I would like you to show me which values have been added.

following the example

1,pedro,2,2
2,pablo,4,2
3,pedro,3,2

I know that the summation is done by making a SELECT id, name, SUM (value1) as sumvalor1

but this demands me a single ROW with the summation and a single name

I would like you to show me something like this:

1,pedro,2,2
3,pedro,3,2
sumavalor1=5

Greetings! I hope you understand what I say.

PS: I want to show the payment history of a person and the total of payments and that the client can see the date and the payment that I made before the sum of those payments. PS: In the same table there are more than 1 people with different names.

  

Appointment in block

    
asked by Nor 27.12.2018 в 10:39
source

1 answer

1

ok friend I realize through your tag that you are working apart from mysql as a php database engine like language and javascript then this can make something easier with what you say

first of all we sometimes want to do everything in a super complicated and unsustainable query then if what you want to do is a select with all the history of buying a client then do it separately

select * from Usuarios where id = @idUsuario

you can then store that in an arraylist or draw it from a single in html now for the total you have another query

select SUM(valor1) as sumavalor1 from Usuarios where id = @idUsuarios

This way it is easy to read and maintain you can also do only the first query and the summation by php,

PS: if you had to filter the information, do a select before and store it in some variables in php, remember that you are using a set of tools that can make your life easier, do not kill yourself using sql Salufos

    
answered by 27.12.2018 / 11:07
source