mysql - 错误代码: 1054 Unknown column 'try.tb_stores.division' in 'on clause'

标签 mysql sql

美好的一天,我尝试运行此查询,但遇到错误,即使该列确实存在于 tb_divisions 中。

有人可以帮我解决这个错误吗:

Unknown column 'try.tb_stores.division' in 'on clause?

-- 2.商店迁移

INSERT INTO `try`.`tb_stores`
(
`try`.`tb_stores`.`subscription`,
`try`.`tb_stores`.`client`,
`try`.`tb_stores`.`division`,
`try`.`tb_stores`.`code`,
`try`.`tb_stores`.`name`,
`try`.`tb_stores`.`location`,
`try`.`tb_stores`.`user`,
`try`.`tb_stores`.`created_at`,
`try`.`tb_stores`.`updated_at`
)
SELECT
1,                                                                          -- subscription
`try`.`tb_clients`.`id` AS `client`,                                        -- client
`try`.`tb_divisions`.`id` AS `division`,                                    -- division
`dba_department`.`code`,                                                    -- code
`dba_department`.`descrip`,                                                 -- name
CONCAT('Region ',`dba_department`.`region_num`) AS region,                  -- location
2,                                                                          -- user
NOW(),                                                                      -- created_at
NOW()                                                                       -- updated_at
FROM `test`.`dba_department`
LEFT JOIN `try`.`tb_clients`
ON `test`.`dba_department`.`company` = `try`.`tb_clients`.`companycode`;

enter image description here

我使用了 LEFT JOIN 但仍然出错。 -- 2. 商店迁移

INSERT INTO `try`.`tb_stores`
(
`try`.`tb_stores`.`subscription`,
`try`.`tb_stores`.`client`,
`try`.`tb_stores`.`division`,
`try`.`tb_stores`.`code`,
`try`.`tb_stores`.`name`,
`try`.`tb_stores`.`location`,
`try`.`tb_stores`.`user`,
`try`.`tb_stores`.`created_at`,
`try`.`tb_stores`.`updated_at`
)
SELECT
1,                                                                          -- subscription
`try`.`tb_clients`.`id` AS `client`,                                        -- client
`try`.`tb_divisions`.`id` AS `division`,                                    -- division
`dba_department`.`code`,                                                    -- code
`dba_department`.`descrip`,                                                 -- name
CONCAT('Region ',`dba_department`.`region_num`) AS region,                  -- location
2,                                                                          -- user
NOW(),                                                                      -- created_at
NOW()                                                                       -- updated_at
FROM `test`.`dba_department`
LEFT JOIN `try`.`tb_clients`
ON `test`.`dba_department`.`company` = `try`.`tb_clients`.`companycode`
LEFT JOIN `try`.`tb_divisions`
ON `try`.`tb_stores`.`division` = `try`.`tb_divisions`.`id`;

最佳答案

您只使用表部门和客户,而不是tb_stores,这就是您收到此错误的原因:

enter image description here

关于mysql - 错误代码: 1054 Unknown column 'try.tb_stores.division' in 'on clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41844780/

相关文章:

PHP 全文搜索未按预期工作

mysql - 获取当前每一天的事件总数

mysql - 在列中获取表行

sql - 编写 SQL 查询时遇到问题 多对多关系

php - 通过 PHP 以当前日期命名数据库表

java - Java 中的 Oracle 主键生成器

使用 MySQL LIMIT 的 ASP.NET GridView 分页

MySQL 舍入怪异

php - while 循环在从表中选择多列时不起作用

sql - 如何从带参数的函数创建 View ?