是否可以根据不同的fk2和>选择此表格式的行列表?日期?
表
pk fk1 fk2值日期
1 1 1 100 1/1/2009
2 1 2 110 1/1/2009
3 1 2 120 5/1/2009
4 1 3 130 1/1/2009
我希望它返回行1,3,4
我只传入fk1
从表中选择*,其中fk1 = 1'和每个fk2的最新日期行?
此致
答案 0 :(得分:2)
Select * from table t where t.fk1=1 and t.date=( select max(date) from table where fk2=t.fk2 and fk1=t.fk1)