我有一个下面的价格表
要求每个产品在单行中有多个价格
我的sql查询是
select a.out_of_stack, product.*,
( select min(price) from temp_attr
where product_id =product.product_id
) as min_price ,
( select max(price) from temp_attr
where product_id = product.product_id
) as max_price from product
left join users a
on a.user_id = product.user_id
where product.category_id in (37903,4707)
and product.product_status in ('0')
and product.draft=0
and a.active=0
and product.product_close=0
and product.price between 10 and 4000
group by product.product_id
使用带有 temp_attr 表的价格进行搜索时,我需要获取产品。
最佳答案
查找 temp_attr
中产品的最高/最低价格:
SELECT MIN(price) , MAX(price) from temp_attr group by product_id
将它们与product
和user
表连接起来:
SELECT a.out_of_stack , product.*, t1.* FROM
product
left join (SELECT MIN(price) , MAX(price) from temp_attr group by product_id ) as t1
on t1.product_id = product.product_id
left join users as a
on a.user_id = product.user_id
where product.category_id in (37903,4707)
and product.product_status in ('0')
and product.draft=0
and a.active=0
and product.product_close=0
and product.price between 10 and 4000
group by product.product_id
关于mysql - 使用 SQL 对多个变体行进行价格搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42159160/