表中字段
单号,           车号, 入仓号
100801      A0001   M102
100801      A0001   M103
100801      A0001   M104
100801      A0001   M102
100802      A0002   M102
100802      A0002   M103
100802      A0002   M105我要得到的数据,一个单号对应一个车,单号唯一的
单号,          车号
100801      A0001
100802      A0002
除去重复的记录
这个SQL语句该怎么写

解决方案 »

  1.   

    select 单号,车号 from 表明 group by 单号,车号
      

  2.   


    select distinct 单号,车号 from t
      

  3.   


    declare @tb table
    (
    单号   nvarchar(10),
    车号   nvarchar(10),
    入仓号 nvarchar(10)
    )insert @tb
    select '100801', 'A0001','M102' union all
    select '100801', 'A0001','M103' union all
    select '100801', 'A0001','M104' union all
    select '100801', 'A0001','M102' union all
    select '100802', 'A0002','M102' union all
    select '100802', 'A0002','M103' union all
    select '100802', 'A0002','M104'select distinct 单号, 车号 from @tb
      

  4.   


    select distinct 单号, 车号 from tb
      

  5.   

    select distinct 单号, 车号 from tb
      

  6.   

    select  单号,车号,from 表明 group by 单号 
    用分组查询
      

  7.   


    select distinct 单号, 车号 from tb
      

  8.   


    declare @tb table
    (
    单号   nvarchar(10),
    车号   nvarchar(10),
    入仓号 nvarchar(10)
    )insert @tb
    select '100801', 'A0001','M102' union all
    select '100801', 'A0001','M103' union all
    select '100801', 'A0001','M104' union all
    select '100801', 'A0001','M102' union all
    select '100802', 'A0002','M102' union all
    select '100802', 'A0002','M103' union all
    select '100802', 'A0002','M104'SELECT DISTINCT 单号,车号 FROM @tb
    SELECT 单号,车号 FROM @tb
    GROUP BY 单号,车号
      

  9.   

    GROUP BY  和 DISTINCT  都对,那个效率高?