gpt4 book ai didi

mysql - sql在subselect中选择多行

转载 作者:行者123 更新时间:2023-11-30 23:23:40 25 4
gpt4 key购买 nike

首先,我知道目前这是不正确的。我知道这是因为它不起作用。话虽如此,如果能帮助我更接近我想要的结果,我们将不胜感激。

我有一个问题:

$query = "SELECT cat.*, 
prod.title AS product,
cat1.title AS category,
(SELECT cat2.*
FROM ic_store_catalog AS cat2
WHERE cat2.parentid = cat.parentid) AS children
FROM ic_store_catalog AS cat
LEFT JOIN ic_products AS prod
ON cat.productid = prod.productid
LEFT JOIN ic_product_categories AS cat1
ON cat.categoryid = cat1.categoryid
WHERE `storeid` = $storeid
AND `column` = $column
AND `parentid` = 0
ORDER BY `the_order` ASC";

这个错误给我:Operand should contain 1 column(s) 作为问题。这存在于保证的子选择中。

现在,当我在 PHP 中使用 print_r 时,我需要实现的是一个结构类似于此的 Array:

[0] => Array
(
[catalogID] => 165
[storeID] => 0
[categoryID] => 7
[parentID] => 0
[productID] => 4
[title] =>
[column] => 1
[the_order] => 1
[cat_order] => 1
[category] => Cookies & Brownies
[children] => Array
(
[0] => Array (
[catalogID] => 166
[storeID] => 0
[categoryID] => 8
[parentID] => 7
[productID] => 5
[the_order] => 1
[cat_order] => 1
[category] => Brownies
)
)
)

如果您能帮助我更接近这个结果,我们将不胜感激。

最佳答案

(选择 cat2.*
来自 ic_store_catalog AS cat2
WHERE cat2.parentid = cat.parentid)

您应该仅将 cat2.* 替换为代表 children 的一列。

关于mysql - sql在subselect中选择多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14346220/

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