Here is my simple table

MariaDB [tutorial]> select * from prices;
+----+------+------+
| id | name | cost |
+----+------+------+
|  1 | A    | 1200 |
|  2 | A    | 2500 |
|  3 | A    | 3000 |
|  4 | B    | 5000 |
|  5 | B    | 7000 |
|  6 | C    | NULL |
+----+------+------+
6 rows in set (0.00 sec)

I want it to give me data as

name   cost
A         6700
B         12000
C         NULL

But my query is not working - 

MariaDB [tutorial]> select name, CASE WHEN ISNULL(DISTINCT sum) THEN sum(cost) 
ELSE NULL END AS cost_sum
    -> from prices group by name;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual 
that corresponds to your MariaDB server version for the right syntax to use 
near 'DISTINCT sum) THEN sum(cost) ELSE NULL END AS cost_sum
from prices group by name' at line 1

-- 
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place. Therefore, 
if you write the code as cleverly as possible, you are, by definition, not 
smart enough to debug it.

--Brian Kernighan

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql

Reply via email to