Answer the question
In order to leave comments, you need to log in
How to display the sum of sql values with a query if the given one goes into a variable?
There is a query that displays all non-repeating values and it works:
$query = "SELECT DISTINCT ".$fields."
FROM tbl_report all_months
".$joins."
WHERE all_months.date > '".$year."-01-01 00:00:00' AND all_months.date < '".$year."-12-31 24:59:59'";
$query = "SELECT SUM ".$fields."
FROM tbl_report all_months
".$joins."
WHERE all_months.date > '".$year."-01-01 00:00:00' AND all_months.date < '".$year."-12-31 24:59:59'";
Answer the question
In order to leave comments, you need to log in
SUM is an aggregation function and can only take 1 argument.
www.tizag.com/mysqlTutorial/mysqlsum.php
If you need to sum columns within a single tuple, write explicitly:
PS
If you consider some kind of statistics, then I doubt that distinct is needed in the first request, most likely the request was made incorrectly
And for starters, open the MySQL manual, read, for example, how to use SUM () correctly, and then, believe me, everything will become clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question