gpt4 book ai didi

mysql - 使用 SELECT 和连接 MySQL?

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

https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_where

这个有效:

SELECT
s.*,
(SELECT ProductName
FROM Products
WHERE SupplierID = s.SupplierID LIMIT 1) AS ProductNames
FROM
Suppliers s

我想使用这样的东西:

SELECT
s.*,
GROUP_CONCAT(SELECT ProductName
FROM Products
WHERE SupplierID = s.SupplierID) AS ProductNames
FROM
Suppliers s

显示每行供应商的位置,即使 ProductNames 为空但它给出错误。

这样的事情可能吗?我知道 LEFT JOIN 也可以。

最佳答案

我想通了

https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_where

SELECT s.*,
(SELECT GROUP_CONCAT(ProductName) FROM Products WHERE SupplierID = s.SupplierID) AS ProductNames
FROM Suppliers s

关于mysql - 使用 SELECT 和连接 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52959630/

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