如何组合同一个表的两行,下一个相同的列显示一个具有不同名称的新列

时间:2022-04-13 23:54:34

EXISRING TABLE

name regno subject_code grade result
abc  1000  cs105        C     pass
abc  1000  it100        D     pass
abc  1000  cs117        B     pass
xyz  1001  cs105        E     pass
xyz  1001  it100        A     pass
xyz  1001  cs117        U     fail

PROPOSED TABLE

name regno subect_code1 grade subjectcode2 grade subjectcode3 grade result
abc  1000  cs105        C     it100        D     cs117        B     pass
xyz  1001  cs105        E     it100        A     cs117        U     fail

1 个解决方案

#1


0  

Use AS to select the column and name it what you want in the results. From looking at what you have though, you would probably need to include the pass/fail for each class group as well right? Same concept would still apply

使用AS选择列并在结果中为其命名。从查看你的内容来看,你可能还需要为每个班组包括通过/失败吗?同样的概念仍然适用

SELECT table1.name, table1.regno, table1.subject_code AS subject_code1, table.grade AS grade1, table1.result AS result1...

Then join in your other data with different aliases.

然后使用不同的别名加入您的其他数据。

#1


0  

Use AS to select the column and name it what you want in the results. From looking at what you have though, you would probably need to include the pass/fail for each class group as well right? Same concept would still apply

使用AS选择列并在结果中为其命名。从查看你的内容来看,你可能还需要为每个班组包括通过/失败吗?同样的概念仍然适用

SELECT table1.name, table1.regno, table1.subject_code AS subject_code1, table.grade AS grade1, table1.result AS result1...

Then join in your other data with different aliases.

然后使用不同的别名加入您的其他数据。