4
How do I sum everything from a table in Mysql for example..
I have the table tb_comment
, then I want to add in each post(id_mark)
the amount of rate it will have in total.
For example the id_user 20
has the rate of 4 in id_mark 10
and the id_user 21
has the rate of 5 in id_mark 10
and will give 9 to total as I do to select this in PDO ?
Is that correct?: SELECT id_mark, SUM(rate) as rate FROM tb_comment GROUP BY id_mark WHERE id_mark=:post_id
– William Alvares
or would that be??:: SELECT SUM(rate) AS total GROUP BY id_user WHERE id_mark=:post_id
– William Alvares
and for me to select for example all values of id_mark only counting as '1' each value?? and not 7 as it is in the image
– William Alvares
@Williamalvares did not get it right. If you want to know only the number of lines, you can use COUNT()
– Bacco
Yes only the number of lines.. Can you give me an example ?
– William Alvares
SELECT COUNT(*) AS lines, SUM(rate) AS total FROM tb_comment WHERE id_user = .....
– Bacco