这些是我创建视图的代码对我来说很好,我只想添加一个字段名:job_type,它来自一个名为Job Type的表。
所以基本上,我只想结合使用VIEW: vinvoices 和TABLE: tjobtypes
我的代码:
CREATE VIEW vinvoicesbymthbyjob
as
select
`vinvoices`.`yymm` AS `yymm`,
`vinvoices`.`location` AS `job_location`,
`vinvoices`.`job_no` AS `job_no`,
format(sum(`vinvoices`.`amount`),0) AS `amount` from `vinvoices`
TJOBTYPES
TJOBS
VINVOICES
提前致谢! :)
答案 0 :(得分:0)
正如我在之前的评论中所说,你必须加入表格。 Here is the documentation。视图只不过是一个查询,但它可以像表一样使用:
SELECT
vinvoices.yymm AS yymm,
vinvoices.location AS job_location,
vinvoices.job_no AS job_no,
format(sum(vinvoices.amount),0) AS amount,
tjobtypes.type_name AS job_type
FROM vinvoices
JOIN tjobs ON tjobs.job_no = vinvoices.job_no
JOIN tjobtypes ON tjobtypes.type_no = tjobs.type_no