MaingroupTable
MubGroupCodeid MainName maincode
1 Health 098
2 Social 078
子组表
SubGroupCodeid SubName subcode
1 Nursing 211
2 Civics 224
SubandMainGroup 表
subandmainid **MubGroupCodeid** **subgroupcodeid**
1 1 1
2 2 2
学生桌
studid studname **subandmainid** (foriegn key of **subandmain group** table)
1 Alex 1
2 siraj 2
然后我想加入并合并studname-maingroupcode-subgroupcode以获得如下所示的输出
Alex-098-211
siraj-078-224
答案 0 :(得分:1)
这将帮助您入门并解释联接。您可能还想对主代码和子代码进行一些转换,但是由于不是100%清楚,它们还不是varchar值,因此我忽略了这一点。
B
答案 1 :(得分:0)
使用连接并通过||
合并所有必需的列select s.studname ||'-'||subG.subcode ||'-' M.maincode
from
Student s join SubandMainGroup subM on s.subandmainid=subM.subandmainid
join SubGroup subG on subG.SubGroupCodeid=subM.subgroupcodeid
join MaingroupTable M on M.MubGroupCodeid=subM.MubGroupCodeid
答案 2 :(得分:0)
使用以下查询解决问题。
select stu.studname + '-'+mgrp.maincode +'-'+sgrp.subcode from Student_ stu
join Maingroup mgrp on stu.studid=mgrp.MubGroupCodeid
join SubGroup sgrp on sgrp.SubGroupCodeid=stu.studid