0

Month wise data Image

Month wise data fetch from date field in mysql.

I have a table name salary_details and my table data looks like attached Image. Please see the image to solve my problem.

i am using following code of php.

"select *, SUM(amount) as amt from salary_details group by month,name"

Usman Rana
  • 11
  • 1
  • Does this answer your question? [How can I return pivot table output in MySQL?](https://stackoverflow.com/questions/7674786/how-can-i-return-pivot-table-output-in-mysql) – Luuk Apr 06 '22 at 07:00

1 Answers1

0

You need to do pivot, check reference here

SELECT Name, ['July'],['August'],['September'] FROM   
(SELECT Name, [Month] , Amount FROM salary_details )Tab1  
PIVOT  
(  
SUM(amount) FOR [Month] IN (['July'],['August'],['September'])
) AS Tab2  
ORDER BY Tab2.Name
Aryan
  • 67
  • 1
  • 5