表中字段
单号, 车号, 入仓号
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语句该怎么写
单号, 车号, 入仓号
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语句该怎么写
select distinct 单号,车号 from t
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 distinct 单号, 车号 from tb
用分组查询
select distinct 单号, 车号 from tb
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 单号,车号