mysql - 当列存在时构建 View 时,在 'on clause' 中获取 #1054 - 未知列。

标签 mysql sql

我正在使用以下代码构建一个 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/

相关文章:

mysql - SQL join left 获取 MAX(date)

mysql连接值之间的差异最小?

Mysql 用另一个表中的值更新 Null 列并重复该顺序

php - 防止 SQL 注入(inject)

php - MySQL中SQL语句的问题

sql - 从当前日期到该月的第一天的两个表中选择日期范围

php - 从数据库中检索数据不适用于此代码

MYSQL:从一列中选择具有多个值的查询

mysql - 如何为特定数据库模式设置 MariaDB 以从 mysql 服务器复制

mysql - 防止第三方连接到 SQL 数据库(来自 config.php 文件)