select distinct(pclassname),id from Iproducts where pclassid between 21 and 28
查询pclassname的时候distinct起作用,但是加上ID就没有去除重复的。
那位大神帮我解决一下。

解决方案 »

  1.   

    select distinct pclassname,id from Iproducts where pclassid between 21 and 28
    或者
    select pclassname,id from Iproducts where pclassid between 21 and 28 group by pclassname,id
      

  2.   

    你这样写当然没去重复啊select *, count(distinct pclassname) Iproducts where pclassid between 21 and 28 group by name
      

  3.   

    ID是主键的话,一放上去就没法去重复了。多个ID对应一个pclassname的话,你只能显示其中一个ID而不是全部显示,否则一行也变为多行了。
      

  4.   

     select distinct pclassname,count(id)  Iproducts where pclassid between 21 and 28 group by name
      

  5.   

    ID就是主键有多个ID对应一个Pclassname