这个语句怎么写?热心参与者皆有分奖励!
现在有两个表tab1,tab2,是一个关于产品检验记录的,一个是物理性能,一个是化学性能,每个产品都有一个样品号,但同一个样品有可能试验多次,比如样品号是K1234-1表示是产品编号为K1234的第1个样品检验记录,K07-1234-2表示是07年产品编号为1234的第2个样品检验记录,tab2中也一样的含义,现在的需求是想一次取出两个表中同一个编号的记录,比如上边的1234的记录,但第一个表中取时间最早的一条记录,tab2中取时间最晚的一条记录,
表机构如下:
create table tab1(riqi datetime, no varchar(10),a1 varchar(6),a2 varchar(6),a3 varchar(6))
insert into tab1
select '2007-02-01 10:45:20 ', 'K07-1234-1 ', '11 ', '12 ', '21 '
union all select '2007-02-01 10:47:20 ', 'K07-1234-2 ', '12 ', '13 ', '23 '
union all select '2007-02-01 10:58:20 ', 'K07-1234 ', '16 ', '17 ', '19 '
union all select '2007-02-01 11:05:20 ', 'K07-1235-1 ', '13 ', '22 ', '22 '
union all select '2007-02-01 11:15:12 ', 'K07-1235-2 ', '21 ', '12 ', '44 '
union all select '2007-02-01 10:45:20 ', 'K07-1235-3 ', '31 ', '32 ', '34 '
union all select '2007-02-01 10:45:20 ', 'K07-1236-1 ', '11 ', '12 ', '21 '
create table tab2(riqi datetime, no varchar(10),b1 varchar(6),b2 varchar(6),b3 varchar(6))
insert into tab2
select '2007-02-01 11:45:20 ', 'K07-1234-1 ', 'A ', 'B ', 'C '
union all select '2007-02-01 11:47:20 ', 'K07-1234-2 ', 'B ', 'F ', 'D '
union all select '2007-02-01 11:58:20 ', 'K07-1234-3 ', 'E ', 'F ', 'G '
union all select '2007-02-01 12:05:20 ', 'K07-1235-1 ', 'T ', 'G ', 'W '
union all select '2007-02-01 11:15:12 ', 'K07-1235-2 ', 'T ', 'E ', 'G '
union all select '2007-02-01 10: