MySQL数据库(社区)版本:5.6.27,Windows 7 Pro x64
我刚刚创建了这个视图:
DELIMITER $$
ALTER ALGORITHM=UNDEFINED DEFINER=`admin`@`%` SQL SECURITY DEFINER VIEW `vw_qb_assembly_component_info` AS (
SELECT
`qb_assembly_components`.`assembly_item_id` AS `assemblyId`,
`ai`.`name` AS `assemblyName`,
`qb_assembly_components`.`component_quantity` AS `componentQuantity`,
`qb_assembly_components`.`component_item_id` AS `item_id`,
`ci`.`name` AS `name`,
`ci`.`item_number_type` AS `item_number_type`,
`ci`.`type` AS `type`
FROM ((`qb_assembly_components`
JOIN `qb_items` `ai`
ON ((`ai`.`item_id` = `qb_assembly_components`.`assembly_item_id`)))
JOIN `qb_items` `ci`
ON ((`ci`.`item_id` = `qb_assembly_components`.`component_item_id`))))$$
DELIMITER ;
我试图查询视图中具有特定
qb_assembly_components
。assembly_item_id
值的行。我尝试了几种在WHERE子句中定义列的方法,但始终会收到错误:“ where子句”中的未知列“ xyz”
以下是我尝试过的版本:
WHERE `qb_assembly_components`.`assemblyId` = 'RR-0T056'
WHERE `qb_assembly_components`.`assembly_item_id` = 'RR-0T056'
WHERE `assemblyId` = 'RR-0T056'
我很困惑我在Google上进行了一些搜索,发现一些结果似乎表明使用别名是可行的方法(上述3个示例中的最后一个示例),但是它没有用。
我究竟做错了什么?
最佳答案
如果您从VIEW
vw_qb_assembly_component_info中选择``
那么where子句应引用视图名称(而不是原始表名称)
WHERE `vw_qb_assembly_component_info`.`assemblyId` = 'RR-0T056'
关于mysql - 为什么我在View SELECT查询上收到带有WHERE子句的“未知列'xyz'”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41659369/