问题描述
尊敬的先生,
我在sql server数据库中有一个表数据,如下所示,其中字段如teacher和class1,class2,.......
老师cls1 cls2 cls3 cls4 cls5 cls6 cls7 cls8 cls9 cls10
Ram r1 r2 r3 r4 r5 r6 r7 r8 r9 r10
Sam s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
Hari h1 h2 h3 h4 h5 h6 h7 h8 h9 h10
Gagan g1 g2 g3 g4 g5 g6 g7 g8 g9 g10
Prakas p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
我想像老师那样把桌子分成下面的五个类似c#
老师cls1 cls2 cls3 cls4 cls5
Ram r1 r2 r3 r4 r5
Sam s1 s2 s3 s4 s5
Hari h1 h2 h3 h4 h5
Gagan g1 g2 g3 g4 g5
Prakas p1 p2 p3 p4 p5
老师cls6 cls7 cls8 cls9 cls10
Ram r6 r7 r8 r9 r10
Sam s6 s7 s8 s9 s10
Hari h6 h7 h8 h9 h10
Gagan g6 g7 g8 g9 g10
Prakas p6 p7 p8 p9 p10
请帮助我。
感谢adv。
respected sir,
i have a table data in sql server database like below where fields like teacher and class1,class2,.......
Teacher cls1 cls2 cls3 cls4 cls5 cls6 cls7 cls8 cls9 cls10
Ram r1r2r3r4r5r6r7r8r9r10
Sam s1s2s3s4s5s6s7s8s9s10
Hari h1h2h3h4h5h6h7h8h9h10
Gagan g1g2g3g4g5g6g7g8g9g10
Prakas p1p2p3p4p5p6p7p8p9p10
I want to split the table like teacher with five classeslike below in c#
Teacher cls1 cls2 cls3 cls4 cls5
Ram r1r2r3r4r5
Sam s1s2s3s4s5
Hari h1h2h3h4h5
Gagan g1g2g3g4g5
Prakas p1p2p3p4p5
Teacher cls6 cls7 cls8 cls9 cls10
Ram r6r7r8r9r10
Sam s6s7s8s9s10
Hari h6h7h8h9h10
Gagan g6g7g8g9g10
Prakas p6p7p8p9p10
kindly help me.
thanks in adv.
推荐答案
Teacher(id, name)<br />
Class(id, teacher_id, name)
不过,让我们假设你坚持这种可怕的方法。设 T
为原始表格, T1
, T2
两个结果。
简单地发出这些:
Still, let's suppose you stick to this horrible approach. Let T
be the original table and T1
, T2
the two resultant ones.
Simply issue these:
INSERT INTO T1(teacher, cls1, cls2, cls3, cls4, cls5) SELECT teacher, cls1, cls2, cls3, cls4, cls5 FROM T;
INSERT INTO T2(teacher, cls6, cls7, cls8, cls9, cls10) SELECT teacher, cls6, cls7, cls8, cls9, cls10 FROM T;
当然,您需要创建 T1
和 T2
表。
这篇关于按字段编号拆分表数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!