在MySQL查询中一起使用DISTINCT和COUNT

问题描述:

是否可能这样:

SELECT DISTINCT COUNT(productId) WHERE keyword='$keyword'

我想要获得与关键字相关联的唯一产品ID的数量.同一产品可能与某个关键字相关联两次,甚至更多,但我希望每个产品ID只能计算1次

What I want is to get the number of unique product Ids which are associated with a keyword. The same product may be associated twice with a keyword, or more, but i would like only 1 time to be counted per product ID

使用

SELECT COUNT(DISTINCT productId) from  table_name WHERE keyword='$keyword'