gpt4 book ai didi

mysql - SQL:未知列 'items.id'关系查询

转载 作者:行者123 更新时间:2023-11-29 12:02:06 25 4
gpt4 key购买 nike

我对此查询有疑问。我认为问题在于找不到项目。之后我对其进行 LEFT OUTER JOIN 操作,但在此之前什么也没做。在开头包含 items 表的最佳解决方案是什么?

SELECT COUNT(*) AS `numrows` FROM (`categories_items`) 
LEFT OUTER JOIN `items_stones` `items_stones` ON `items`.`id` = `items_stones`.`item_model_id`
LEFT OUTER JOIN `items` ON `items`.`id` = `categories_items`.`item_model_id`
WHERE ( `items_stones`.`stone_model_id` = 1 ) AND `categories_items`.`category_model_id` = 1

最佳答案

将查询更改为如下所示,基本上交换LEFT JOINS

    SELECT COUNT(*) AS `numrows` 
FROM `categories_items`
LEFT OUTER JOIN `items` ON `items`.`id` = `categories_items`.`item_model_id`
AND `categories_items`.`category_model_id` = 1
LEFT OUTER JOIN `items_stones` ON `items`.`id` = `items_stones`.`item_model_id`
AND `items_stones`.`stone_model_id` = 1;

关于mysql - SQL:未知列 'items.id'关系查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32192003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com