我有以下表格:
main_table
stu_name
stu_mark
mark_table
s_name
pos_mark
neg_mark
使用数据:
main_table
stu_name stu_mark
-------- --------
Rob 20
sally -10
Dave 30
Merve -50
期望的输出:
mark_table
s_name pos_mark neg_mark
------- -------- --------
Rob 20 NULL
Sally NULL -10
Dave 30 NULL
Merve NULL -5
答案 0 :(得分:1)
尝试:
INSERT INTO mark_table
select stu_name s_name,
case when stu_mark >= 0 then stu_mark end pos_mark,
case when stu_mark < 0 then stu_mark end neg_mark
from main_table
(假设您希望在pos_mark中填充0的标记,而不是在neg_mark列中填充。)