-1

my task is to combine several rows into one column, only the rule is that some of the things that are repeated should stay. Task is to the student table. I will give an example:

Student_ID | Sex | Field_Of_Study | Department | Term | Subject | Grade_1 | Grade_2 | Grade_3|
-----------|-----|----------------|------------|------|---------|---------|---------|--------|
      1       M        Comp_scie      Inf        3       Electr      2         3        0
      1       M        Comp_scie      Inf        3       Python      4         0        0
      1       M        Comp_scie      Inf        3       Java        3         4        0

And my task is to make it looks like that:

Student_ID | Sex | Field_Of_Study | Department | Term | Subject_1 | Grade_11 | Grade_12 | Grade_13| Subject_2 | Grade_21 | Grade_22 | Grade_23| Subject_3 | Grade_31 | Grade_32 | Grade_33|
-----------|-----|----------------|------------|------|-----------|----------|----------|---------|-----------|----------|----------|---------|-----------|----------|----------|---------|
      1       M        Comp_scie      Inf        3       Electr        2           3        0        Python        4         0            0         SQL         2         3        0

Is there any option to make it looks like this using SQL ?

I tried to create a script that will arrange this table, but I have too little skills to connect it in this way or at least similar.

Kacper
  • 1
  • I'd assume this being vendor specific; at least for MS SQL you might want to peek [here](https://stackoverflow.com/questions/8005846/sql-server-combining-multiple-rows-into-one-row). – Aconcagua May 26 '23 at 07:39

1 Answers1

0

Seems like your Student_Id isn't unique so make it either unique or assign a primary key to it so it'll accept only single value.

Hope this will help you achieving the desired output.

Thanks & Regards. For any requirements or more information about the given solution cmnt down, I'll share it.