如何在mysql中选择不同的列总和[关闭]

I want to select the sum of different cites according to time column in my database. The required result will be as like below image.

Please have a look at the image.

enter image description here

AND finally I want to print the above data in my web page using PHP.

If I understand you write, may be something like:

SELECT city, sum(amount) 
FROM table_name 
WHERE MONTH(date_column)=12 
GROUP BY city;

you can use a combination of SUM(CASE...) and GROUP BY clause. Something like this

SELECT
   city,
   SUM(CASE WHEN MONTH(orderDate)=1 THEN amount ELSE 0 END) as january,
   SUM(CASE WHEN MONTH(orderDate)=2 THEN amount ELSE 0 END) as february,
   SUM(CASE WHEN MONTH(orderDate)=3 THEN amount ELSE 0 END) as march
FROM orders
GROUP BY city

I'm assuming the table name is ORDERS and using the column orderDate to identify the mounth.

Good luck, bro.