This is my query:
SELECT
`i`.`itemtype` AS `Item`,
`p`.`name`
(SELECT SUM(`i`.`count`) AS `Count` WHERE `itemtype` = 2148),
(SELECT SUM(`i`.`count`) * 100 AS `Count1` WHERE `itemtype` = 2152),
(SELECT SUM(`i`.`count`) * 10000 AS `Count2` WHERE `itemtype` = 2160)
FROM `player_items` AS `i`
LEFT JOIN `players` AS `p` ON (`p`.`id` = `i`.`player_id`)
WHERE `i`.`itemtype` IN (2148, 2152, 2160)
GROUP BY `i`.`itemtype`
LIMIT 0, 30
When I run the above query in mysql, I get this error message:
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'SELECT SUM(`i`.`count`) AS `Count` WHERE `itemtype` = 2148)
, (SELECT SUM(`i`' at line 4
I completely don’t understand what does that mean as I’m a begginer in MySQL.
You’re missing a comma after this column:
Consider this query instead:
To SUM those three columns together, you could:
Or you could add another
CASEThe CASE statements makes it unnecessary for you to have to run your three additional
SELECTstatements to return the same results.