a表里数据如下:  名称    型号     数量
  光驱    52x       2
  光驱    42x       2
  鼠标    光电      2
  光驱    42x       2
我用select distinct 名称,型号 from a  查询出:
  名称           型号
  光驱       48x       
  光驱       52x       
  鼠标       光电   
但我怎么才能知道用select distinct 名称,型号 from a得出3条记录。

解决方案 »

  1.   

    @@ROWCOUNT
    返回受上一语句影响的行数。
      

  2.   

    select count(*) from
    (select distinct 名称,型号 from a)a
      

  3.   

    select count(9) from a group by 名称,型号,数量
      

  4.   

    如果数量相同
    select distinct 名称,型号,数量 from TB如果数量不相同(使用min或max)
    select a.* from TB a , 
    (select 名称,型号,min(数量) as 数量 from TB group by 名称,型号) b
    where a.名称=b.名称 and a.型号=b.型号 and a.数量=b.数量
      

  5.   

    select distinct 名称,型号,count(数量) from a
      

  6.   

    select distinct 型号,名称 from a