22,207
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb') is not null
drop table tb
create table tb(type varchar(20),accessoryNo varchar(20),deviceNo varchar(10),lastTime int)
insert tb
select 'A','s10','z11',10 union all
select 'B','s10','z11',11 union all
select 'C','s11','z12',5 union all
select 'A','s10','z11',9 union all
select 'A','s10','z13',9 union all
select 'B','s10','z11',3
create table #t2(
序号 int)
declare @sql nvarchar(4000)
set @sql1=N'insert #t2 select lastTime from tb group by type,accessoryNO'
exec(@sql)
drop table tb
insert into #t2 exec(@sql)