Islam Ahmady
Islam Ahmady

Reputation: 81

MySQL Table -> How to Shift Column Data to the next Column and bring the last column to the first place (Rotating Columns Data)

I have this problem - where i have (time Schedule) saved in mysql table the table is for example like this :-

+----+--+------+--+--+--------------+--+--------------+
| day |  | Group A  |  |  |  Group B   |  | Group C
+----+--+------+--+--+--------------+--+--------------+
|  sat|  | physics  |  |  |   Language |  | Algebra
|  sun|  | Chemistry|  |  |   Math     |  | Science
|  mon|  | History  |  |  |   French   |  | GYM
|  ...|  | .....    |  |  |  .......   |  |
+-----+--+----------+--+--+------------+--+-----------+

So at the end of every month - there is a rotation in the schedule - So the result should be

+----+--+------+--+--+--------------+--+--------------+
| day |  | Group A  |  |  |  Group B   |  | Group C
+----+--+------+--+--+--------------+--+--------------+
|  sat|  | Algebra  |  |  |   physics  |  | Language
|  sun|  | Science  |  |  |   Chemistry|  | Math
|  mon|  | GYM      |  |  |   History  |  | French
|  ...|  | .....    |  |  |  .......   |  |
+-----+--+----------+--+--+------------+--+-----------+

SO the subjects of Group B is the Subject of Group A ...> See the tables you should understand it better

So it is like rotation of the columns - i have a server side script that will run once at the end of the month to update the schedule

except i don't have any clue of how to achieve this with MySql - also i have a quite large number of groups (32 to be specific )

so any idea to how to reach this result ?

Upvotes: 0

Views: 139

Answers (1)

Strawberry
Strawberry

Reputation: 33945

Not an answer. Too long for a comment.

An example of a normalised design might look like this

day  group_ref subject
sat  A         physics  
sat  B         language   
sat  C         algebra
sun  A         chemistry
sun  B         math     
sun  C         science
mon  A         history  
mon  B         french   
mon  C         gym

Note however that there is scope here for further optimisation

Upvotes: 1

Related Questions