Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两列
product productactual
以及以下数据:
shoes NULL slippers NULL shoes sandals slippers NULL sandals shoes
我必须计算我正在使用的产品数量,Count (coalesce(Productactual,product))但它没有在查询中进行任何更改或在两列中计算产品的新想法。
Count (coalesce(Productactual,product))
如果要计算每个产品的条目,则需要使用 COALESCE 表达式作为分组项:
SELECT COALESCE(productactual, product) AS product, COUNT(*) AS productcount FROM atable GROUP BY COALESCE(productactual, product) ;