I have a main table which contains all columns
student id name subject marks class
123 John Maths 56 7
234 Meth Maths 78 8
456 Jes Science 67 7
678 Tom Science 89 8
879 Ria Maths 92 7
890 Carl Science 88 8
654 Gerd Science 77 8
From the above table I want to create two tables where student_id acts as the primary key, and in 1st table I want to extract the student_id, name of all the students where class=8 and in 2nd table I want to put in student_id, name, subject and marks of students from table 1.
Table 1
student id name
234 Meth
678 Tom
890 Carl
654 Gerd
Table 2
student id name subject marks
234 Meth Maths 78
678 Tom Science 89
890 Carl Science 88
654 Gerd Science 77
How can I do this in Teradata SQL or Python? The above data is just an example. I am dealing with a huge amount of data at once. So I want to find the best way possible.
Thank you:)
2
Answers
class and name are both reserved words in Teradata, which is why double-quotes.
p.s. What kind of a student name is Meth, anyway? Is this is a chemistry class or mathematics?
SQL:
Python: