Recently, I'm trying to decrease the number of queries by joining unnecessary ones.
in this very case I came to a query that I should have used two queries : one to get the sum of all options and the other is the rows of the same table
SELECT `id`, `text`,`count`, SUM(`count`) AS sumoption
FROM _options
But when I'm trying to run this query , the result will be only one row , and I think its because I added SUM(count) . I know i should use group by to solve this issue but the table schema is not that simple .
id text count
1 Honda 1
2 Benz 0
3 Toyota 1
now the sum should be 2 and the it should list all options and their values.
How can I make this happen ?
PS. : The expected outcome :
Honda 1
Benz 0
Toyota 1
Sum of counts : 2
GROUP BYPlease post an example of what the output should be from the data you posted above.group byclauses.