0
Month Type Amount
Jan   B1   951
Feb   B1   1000
Mar   B1   850
Jan   B2   900
Feb   B2   920
Mar   B2   1000

I am looking to convert the data into

Type Jan Feb  Mar 
B1   951 1000 850
B2   900 920  1000

Thank you

  • 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) – Tangentially Perpendicular Sep 29 '22 at 02:35
  • Unclear. Is the database MySQL or HANA? Also, please post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Sandra Rossi Sep 29 '22 at 07:15

1 Answers1

0

You can do in this way

SELECT
    type,
    SUM(CASE WHEN month = 'Jan' THEN amount ELSE 0 END) AS Jan,
    SUM(CASE WHEN month = 'Feb' THEN amount ELSE 0 END) AS Feb,
    SUM(CASE WHEN month = 'Mar' THEN amount ELSE 0 END) AS Mar
FROM
    t1
GROUP BY
    type

Check out this db fiddle

learning
  • 608
  • 5
  • 15