gpt4 book ai didi

Mysql 多条件查询

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

我试图进行这样的查询:

$query= "SELECT a.virtuemart_category_id, 
a.virtuemart_product_id,
b.product_name,
b.product_desc,
c.product_price,
d.virtuemart_media_id,
e.file_url
FROM wgny6_virtuemart_product_categories a
LEFT JOIN wgny6_virtuemart_products_en_gb b
ON a.virtuemart_product_id = b.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_product_prices c
ON b.virtuemart_product_id = c.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_product_medias d
ON b.virtuemart_product_id = d.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_medias e
ON d.virtuemart_media_id = e.virtuemart_media_id
WHERE b.product_name IS NOT NULL";

但我希望只有当 a.virtuemart_category_id= $id 时才会发生这种情况。但我不知道如何添加该条件。

最佳答案

简单地添加额外的where条件

 AND a.virtuemart_category_id = $id 

在查询末尾。

SELECT a.virtuemart_category_id,a.virtuemart_product_id,b.product_name,b.product_desc, c.product_price,d.virtuemart_media_id,e.file_url 
FROM wgny6_virtuemart_product_categories a
LEFT JOIN wgny6_virtuemart_products_en_gb b ON a.virtuemart_product_id=b.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_product_prices c ON b.virtuemart_product_id=c.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_product_medias d ON b.virtuemart_product_id=d.virtuemart_product_id
LEFT JOIN wgny6_virtuemart_medias e ON d.virtuemart_media_id=e.virtuemart_media_id
WHERE b.product_name IS NOT NULL AND a.virtuemart_category_id = $id

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

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