我正在使用以下代码构建一个 sql View :
create or replace view vw_fill_thresholds as
SELECT waypoint_loc.name,
material_typ.description as material,
fill_thresholds.can_size,
fill_thresholds.threshold,
units.description as unit,
fill_thresholds.post_threshold_cost as ptc,
fill_thresholds.post_threshold_unit_id as ptu
FROM fill_thresholds, fill_locations, material_type, units, waypoint_locations
left join `waypoint_locations` `waypoint_loc` on(`waypoint_locations`.`id` = `fill_locations`.`waypoint_id`)
left join `material_type` `material_typ` on(`material_type`.`id` = `fill_locations`.`material`)
WHERE fill_thresholds.fill_id = fill_locations.id
and fill_locations.unit_id = units.unit_id
and fill_thresholds.deleted = 0;
我的第一个问题是: 我不知道我是否朝着正确的方向前进,但基本上我想做的是使用 fill_locations 表中的外键来获取 Material 和 wabpoints 表中的字段,该外键由我拥有的键引用在 fill_threshold 表中。
我的第二个问题是:
如果我知道 fill_locations 表中存在 waypoint_id,为什么在执行该代码时会收到错误“#1054 - 'on Clause' 中的未知列 'fill_locations.waypoint_id'
”?
如有任何帮助,我们将不胜感激
最佳答案
FROM fill_thresholds
left join fill_locations on fill_thresholds.fill_id = fill_locations.id
and fill_thresholds.deleted = 0
left join units on fill_locations.unit_id = units.unit_id
left join waypoint_locations on `waypoint_locations`.`id` = `fill_locations`.`waypoint_id`
left join `material_type` on `material_type`.`id` = `fill_locations`.`material`
将您的 from
条件更改为上述条件,从而使用适当的 join
。您的查询在语法方面不正确。 (表格使用了两次)
关于mysql - 当列存在时构建 View 时,在 'on clause' 中获取 #1054 - 未知列。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32728865/