创建视图时mysql union all

时间:2013-05-01 19:04:03

标签: mysql

我有以下代码,如果我将代码作为sql脚本运行它可以工作,但如果我想从它创建一个视图我得到这个错误:1166 - 不正确的列名''

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'

任何帮助都会非常好。

谢谢!

1 个答案:

答案 0 :(得分:2)

在你的第二个查询(第一个UNION ALL)中,你有第三列:

'' AS ``

这是无效的 - 删除AS子句,一切都应该没问题。