美好的一天我试图运行此查询,但即使列在tb_divisions中存在,我也遇到了错误。
有人可以帮我解决这个错误:
'on子句中的未知列'try.tb_stores.division'?
- 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`;