美好的一天,我尝试运行此查询,但遇到错误,即使该列确实存在于 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`;
我使用了 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`;
最佳答案
关于mysql - 错误代码: 1054 Unknown column 'try.tb_stores.division' in 'on clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41844780/