-2

使用下表

table1(id,questionid,response,points)

价值观

1,1,'yes',4

2,1,'no',4

3,1,'copper',2

4,2,'yes',1

5,2,'yes',2

想要插入数据 table1table2(id,ques1,point1,ques2,point2,ques3,point3,ques4,point4,ques5,point5)

插入响应,将值指向对应的问题 1d

如果 questionid=1

insert into table2 values ques1='yes' and points=4

表2输出

id,ques1,point1,ques2,point2,ques3,point3,ques4,point4,ques5,point5

1  'yes'  4      'yes'  2      'no'  2    ..........
4

1 回答 1

0

你的样本似乎有一两个错误,但我认为你想要类似的东西:

SELECT id,
    q1.response, q1.points,
    q2.response, q2.points,
    q3.response, q3.points,
    q4.response, q4.points
    q5.response, q5.points
INTO table2
FROM table1 q1
    JOIN table1 q2 ON q1.questionid = q2.questionid
    JOIN table1 q3 ON q2.questionid = q3.questionid
    JOIN table1 q4 ON q3.questionid = q4.questionid
    JOIN table1 q5 ON q4.questionid = q5.questionid
WHERE q1.id = 1 AND q2.id = 2 AND q3.id = 3 AND q4.id = 4 AND q5.id = 5
于 2013-11-13T02:12:02.667 回答