这是我的数据
newCatCols
=====
id sku name
---------------
1 4001 Black
2 4031 Red
3 4021 Black
4 4041 Blush
products
=====
id sku Price
---------------
1 4001 123
2 4031 232
3 4021 453
4 4041 233
这是我的查询
SELECT COUNT( * ) AS numTotal
FROM `products`
INNER JOIN `colors` ON `products`.`sku` = `colors`.`sku`
WHERE (
`name` = 'Apple_Black'
OR `name` = 'Black'
OR `name` = 'Black_Aubergine'
OR `name` = 'Black_Blush'
OR `name` = 'Black_Slate'
OR `name` = 'Black_Turquoise'
OR `name` = 'Red_Black'
OR `name` = 'Sapphire_Black'
OR `name` = 'Multi Apple'
)
AND `status` = '1'
AND `category` = 'sig'
GROUP BY `products`.`sku`
ORDER BY `products`.`rank` ASC
理想情况下,如果我只是更改此行将是完美的SELECT COUNT( * ) AS numTotal
以某种方式只修改它以使其工作?数据当前返回行值为1的产品列表,因此它只是循环而不计算所有行的总值。
它应该只显示返回的总数,例如应该显示4
Output
=====
numTotal
---------------
4
答案 0 :(得分:1)
这将返回符合您条件的不同产品SKU的数量:
SELECT COUNT(distinct `products`.`sku`) AS numTotal
FROM `products`
INNER JOIN `colors` ON `products`.`sku` = `colors`.`sku`
WHERE `name` in ('Apple_Black'
,'Black'
,'Black_Aubergine'
,'Black_Blush'
,'Black_Slate'
,'Black_Turquoise'
,'Red_Black'
,'Sapphire_Black'
,'Multi Apple'
)
AND `status` = '1'
AND `category` = 'sig'