gpt4 book ai didi

MySQL 慢速分组查询

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

我有6张 table 1. 产品介绍2. 属性一3.产品和属性pa(ID、pID、aID)4、公司c5. 用户 u6. 公司和用户cu(ID、cID、uID)

现在在管理中我想查看公司产品及其属性。

SELECT p.ID, p.name
from products p
LEFT JOIN Product and Attribute pa ON pa.pID = p.ID
LEFT JOIN Attributes a ON a.pID = pa.aID
LEFT JOIN Company and User cu ON cu.UiD = p.uID AND cu.cID = 121 (spcific company id)
WHERE 1
GROUP BY p.ID

最佳答案

MySQL , GROUP BY 意味着 ORDER BY

如果不需要特定顺序,请添加ORDER BY NULL

By default, MySQL sorts all GROUP BY col1, col2, ... queries as if you specified ORDER BY col1, col2, ... in the query as well. If you include an ORDER BY clause explicitly that contains the same column list, MySQL optimizes it away without any speed penalty, although the sorting still occurs. If a query includes GROUP BY but you want to avoid the overhead of sorting the result, you can suppress sorting by specifying ORDER BY NULL. For example:

关于MySQL 慢速分组查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143784/

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