0
我有以下代码,如果我将代码作为sql脚本运行,但如果我想从中创建视图,则出现此错误:1166 - 错误的列名''mysql union all创建视图时
select `c`.`package_id` AS `package_id`,
`c`.`student_id` AS `student_id`,
`bs`.`name` AS `stud_name`,
`c`.`payed_date` AS `payed_date`,
(case `c`.`type` when 'e' then 'Vizsgadíj' when 'c' then 'Tanfolyam díj' else '' end) AS `name`,
`c`.`course_price` AS `price`,
`c`.`pay_form` AS `pay_form`,
`c`.`venue_id` AS `venue_id`
from (`bma_student_pays` `c`
join `bma_students` `bs` on((`bs`.`id` = `c`.`student_id`)))
union all
select '0' AS `0`,'0' AS `0`,'' AS ``,`e`.`making_date` AS `making_date`,`e`.`name` AS `name`,`e`.`price` AS `price`,`e`.`type` AS `type`,`e`.`venue_id` AS `venue_id`
from `bma_extra_makings` `e`
union all
select '','','',i.inv_due,i.inv_name,i.inv_amount,i.`mode`,i.venue_id
from bma_invoices i
where i.inv_type='K'
任何帮助都会很好。
谢谢!
我会upvote这个,如果我可以:)我认为你有它! – Chris 2013-05-01 19:07:17
此外,所有列在第一个查询中都是别名。不需要(也可能不正确)将联合查询中的列别名与第一个查询中的列别名不同。 OP可以完全关闭第二个查询的别名。 – 2013-05-01 19:08:34
@DanJ:绝对,但是这不会破坏视图的创建。 – PinnyM 2013-05-01 19:14:48