读书人

求SQL 句,该如何解决

发布时间: 2012-01-30 21:15:58 作者: rapoo

求SQL 句
表: 
Year int ,Month int, GID int, Price int
年,月,商品,采格
求全部商品,最後一次采的格。

[解决办法]
表: 
Year int ,Month int, GID int, Price int

select * from 表 a
where not exists (
select 1 from 表
where GID=a.GID
and ([Year]> a.[Year]
or [Year]=a.[Year]
and [Month]> a.[Month]
)
)

读书人网 >SQL Server

热点推荐