I have a SELECT Query which should have several nested SELECT Queries from the same table, but different WHERE clauses to produce new columns.
The problem is that each sub query in its single form runs good, but when they turn into sub-queries, MySql throws an ERROR.
Here is My SQL :
SELECT user,
(SELECT SUM(amount) from my_table WHERE type='form1' group by user) as form1,
(SELECT SUM(amount) from my_table WHERE type='form2' group by user) as form2,
(SELECT SUM(amount) from my_table WHERE type='form3' group by user) as form3,
(SELECT SUM(amount) from my_table WHERE type='form4' group by user) as form4,
(SELECT SUM(amount) from my_table WHERE type='form5' group by user) as form5,
(SELECT SUM(amount) from my_table WHERE type='form6' group by user) as form6
from my_table group by user;
I want the Query to produce this structure:
user | form1 | form2 | form3 | form4 | form5 | form6
| | | | | |
How should I edit this SQL?
as form6.