Using DISTINCT and COUNT together in a MySQL Query

前端 未结 7 867
旧巷少年郎
旧巷少年郎 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.

    0 讨论(0)
提交回复
热议问题