错误代码:1054'on子句'中的未知列'try.tb_stores.division'

时间:2017-01-25 06:22:24

标签: mysql sql

美好的一天我试图运行此查询,但即使列在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`;

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`;

1 个答案:

答案 0 :(得分:0)

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

enter image description here