Using DISTINCT and COUNT together in a MySQL Query

前端 未结 7 926
旧巷少年郎
旧巷少年郎 2020-11-30 22:04

Is something like this possible:

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

What I want is to get the number of unique pro

7条回答
  •  忘掉有多难
    2020-11-30 22:57

    I would do something like this:

    Select count(*), productid
    from products
    where keyword = '$keyword'
    group by productid
    

    that will give you a list like

    count(*)    productid  
    ----------------------
     5           12345   
     3           93884   
     9           93493    
    

    This allows you to see how many of each distinct productid ID is associated with the keyword.

提交回复
热议问题