gpt4 book ai didi

php - Mysql查询的问题

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

我长期以来一直在通过检查相同字段来尝试一个查询。我的查询是这样的

SELECT DISTINCT products.products_id,products_description.products_title, products_sizes.size_id, products_sizes.size_title,products_sku.sku     
FROM products_description
LEFT JOIN products ON products_description.products_id = products.products_id
LEFT JOIN products_sizes ON products_description.products_id = products_sizes.products_id
LEFT JOIN product_stock_history ON product_stock_history.products_id = products.products_id
LEFT JOIN products_sku ON products_sku.size_id = products_sizes.size_id
WHERE products.enable_stock_management = '1'
AND products.products_id != '-11'

这会检索如下结果

enter image description here

但我想通过检查 sizeid 是否不同来检索如下详细信息,然后仅显示,否则检索第一条记录

enter image description here

这可以实现吗?

最佳答案

我认为这会如你所期望的那样工作

SELECT DISTINCT products.products_id,
products_description.products_title,
products_sizes.size_id,
products_sizes.size_title,
products_sku.sku
FROM products_description
LEFT JOIN products ON products_description.products_id = products.products_id
LEFT JOIN products_sizes ON products_description.products_id = products_sizes.products_id
LEFT JOIN product_stock_history ON product_stock_history.products_id = products.products_id
LEFT JOIN products_sku ON products_sku.size_id = products_sizes.size_id
WHERE products.enable_stock_management = '1'
AND products.products_id != '-11'
GROUP BY size_id,
size_title

关于php - Mysql查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43654837/

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