日期:2014-05-18 浏览次数:20575 次
use Tempdb go --> --> if not object_id(N'Tempdb..#T') is null drop table #T Go Create table #T([商品编号] int,[采购日期] Datetime,[采购价] int) Insert #T select 10001,'2011-02-03',10 union all select 10002,'2011-02-03',15 union all select 10001,'2011-03-05',12 union all select 10003,'2011-03-05',14 union all select 10002,'2011-03-14',16 union all select 10003,'2011-03-14',13 Go Select * from #T AS a WHERE NOT EXISTS(SELECT 1 FROM #T WHERE [商品编号]=a.[商品编号] AND [采购日期]>a.[采购日期]) /* 商品编号 采购日期 采购价 10001 2011-03-05 00:00:00.000 12 10002 2011-03-14 00:00:00.000 16 10003 2011-03-14 00:00:00.000 13 */
------解决方案--------------------