我正在尝试运行此查询:
SELECT
gc_category_products.product_id,
LEAST(IFNULL(NULLIF(saleprice, 0), price),price) AS sort_price,
GROUP_CONCAT(CONVERT(category_id, CHAR(8))) AS cats
FROM
(`gc_category_products`)
JOIN `gc_products` ON `gc_category_products`.`product_id` = `gc_products`.`id`
WHERE
`category_id` = '31'
OR `category_id` = '35'
OR `category_id` = '30'
OR `category_id` = '36'
OR `category_id` = '37'
OR `category_id` = '34'
AND
`enabled` = 1
GROUP BY
`product_id`
LIMIT 10
在cats
字段中,它只返回一个数字,如果我取出所有 WHERE 子句,它会返回一个逗号分隔的列表,但我需要这些 WHERE 来过滤我的数据。
有任何想法吗?
样本数据
gc_category_products
--------------------------
product_id | category_id |
--------------------------
3 | 31 |
3 | 18 |
4 | 35 |
4 | 21 |
gc_products
-----------------------------------
| id | price | saleprice | enabled|
-----------------------------------
| 3 | 23.00 | 0.00 | 1 |
| 4 | 50.00 | 0.00 | 1 |
expected result
--------------------------------
product_id | sort_price | cats |
--------------------------------
| 3 | 23.00 | 31,18|
| 4 | 50.00 | 35,21|