select a.* from tb a,
(select 产品编号,日期=max(日期) from tb group by 产品编号) b
where a.产品编号=b.产品编号 and a.日期=b.日期
(select 产品编号,日期=max(日期) from tb group by 产品编号) b
where a.产品编号=b.产品编号 and a.日期=b.日期
试试这句(没测试)Select id, 产品编号,单价, max(日期) as 日期 from 表 group by id 产品编号 单价
create table tb(id int, 産品編號 varchar(20),單價 numeric(10,2), 日期 datetime)
Insert into tb
select '1','01001','20','2004-11-1'
union all select '2','01001','20','2004-11-2'
union all select '3','01002','20','2004-11-10'
union all select '4','01002','20','2004-11-11'
union all select '5','01003','20','2004-11-21'select a.* from tb a,
(select 産品編號,日期=max(日期) from tb group by 産品編號) b
where a.産品編號=b.産品編號 and a.日期=b.日期
order by a.id--結果
id 产品编号 单价 日期
------------------------------------------------------------------
2 01001 20.00 2004-11-02 00:00:00.000
4 01002 20.00 2004-11-11 00:00:00.000
5 01003 20.00 2004-11-21 00:00:00.000
(select 产品编号 ,max(日期)as 日期 from ttt1 group by 产品编号)a
on a.产品编号=b.产品编号 and a.日期=b.日期 order by id
select 1 from (select max( 日期)as 日期,产品编号 from ttt1 b group by b.产品编号)b where b.日期=a.日期 and b.产品编号=a.产品编号) order by a.产品编号
t.日期 in(select max(日期) from tb b where t.日期=b.日期)
select t.* from tb t where
日期 =(select max(日期) from tb b where t.产品编号=b.产品编号)
order by t.id/*测试结果
id 产品编号 单价 日期
----------- ---------- ----------- ------------------------------------------------------
2 01001 20 2004-11-02 00:00:00.000
4 01002 20 2004-11-11 00:00:00.000
5 01003 20 2004-11-21 00:00:00.000(所影响的行数为 3 行)
*/