0

I am tackling a problem where I have to convert Table 1 to Table 2 using mysql

Table 1

Table 2

Table 2 structure is only define. How can I go about this? I have tried using union statement but am unable to convert Has on Monday to Monday as the column value

1 Answer 1

2

You should write your query as this:

SELECT student, class, 'Monday' AS weekday
FROM table_1
WHERE has_on_monday='T'
UNION ALL
SELECT student, class, 'Tuesday' AS weekday
FROM table_1
WHERE has_on_tuesday='T'
UNION ALL
....

if you want to insert the result to table_2, use a INSERT query:

INSERT INTO table_2 (student, class, weekday)
SELECT ...the select query above...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.