在以下查询中
mysql> select
-> what_to_wear_under,
-> (select group_concat(value) from eav_attribute_option_value where option_id in (what_to_wear_under) and store_id = 1 ) as what_to_wear_under
-> from
-> catalog_product_flat_1 where brief_coverage is not null and brief_coverage > 0 limit 1\G
*************************** 1. row ***************************
what_to_wear_under: 2028,2031,2032
what_to_wear_under: Churidar Kurtas
1 row in set, 2 warnings (0.00 sec)
what_to_wear_under在(what_to_wear_under)中使用 option_id只有一个ID时有三个值。
但如果我直接使用值,则正确返回值
mysql> select what_to_wear_under, (select group_concat(value) from eav_attribute_option_value where option_id in (2028,2031,2032) and store_id = 1 ) as what_to_wear_under from catalog_product_flat_1 where brief_coverage is not null and brief_coverage > 0 limit 1\G
*************************** 1. row ***************************
what_to_wear_under: 2028,2031,2032
what_to_wear_under: Churidar Kurtas,Denims,Dresses
1 row in set (0.00 sec)
您能帮忙我们如何修改查询一来获得三个值吗?
答案 0 :(得分:0)
你无法与这样的列进行比较,无论是否包含以逗号分隔的值,它都会将其视为1值。
你可以使用喜欢这个(我不确定mysql语法所以也许你将不得不用concat调整它):
select
-> what_to_wear_under,
-> (select group_concat(value) from eav_attribute_option_value where what_to_wear_under like concat('%',option_id,'%') and store_id = 1 ) as what_to_wear_under
-> from
-> catalog_product_flat_1 where brief_coverage is not null and brief_coverage > 0 limit 1\G