我正在尝试使用union创建新表, 这些代码有什么问题?
insert into chart
select months, field, value from (
select hp.months, 'ActualBookings2014' as field, hp.ActualBookings2014 as value
FROM hp_metglobal.hp
UNION
select hp.months, 'TargetBookings' as field, hp.TargetBookings as value
FROM hp_metglobal.hp
UNION
select hp.months, 'ActualBookings2013' as field, hp.ActualBookings2013 as value
FROM hp_metglobal.hp
)
答案 0 :(得分:0)
请使用内表的别名:
insert into chart
select months, field, value from ((
select hp.months,
'ActualBookings2014' as field,
hp.ActualBookings2014 as value
FROM hp_metglobal.hp
UNION
select hp.months,
'TargetBookings' as field,
hp.TargetBookings as value
FROM hp_metglobal.hp
UNION
select hp.months,
'ActualBookings2013' as field,
hp.ActualBookings2013 as value
FROM hp_metglobal.hp
) as t)