0

The table I have right now is this: enter image description here

Is there a way in MySQL to manipulate and spread the table to: enter image description here

  • Possible duplicate of [MySQL pivot table](https://stackoverflow.com/questions/7674786/mysql-pivot-table) – Sam M Mar 14 '19 at 18:40

1 Answers1

0

This is called records to columns conversion or pivot.
The general query structure is, done with a GROUP BY , CASE END and some aggregate function like MAX, MIN or SUM. In MySQL/MariaDB or anny database system which does not have a PIVOT() kind of function
Where MAX() and MIN() can pivot every datatype, SUM() is only suitable for numeric datatypes.

SELECT 
   Name
 , SUM(CASE WHEN Cycle = 'weekly' THEN 1 ELSE 0 END) AS weekly
 ..
 ..
FROM
 t
GROUP BY 
 Name

Note because SQL tables when stored and selections off SQL tables are by SQL definition orderless so the result off this query is nondeterministic (random), there wasn't anny column in your data example which could be used to make a deterministic (fixed) order by

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34