高分求一SQL 查询语句。我有一张表 如图:我想查出的结果应该是每一个code时间最新的一条,应该有4条结果

[复制链接]
查看11 | 回复3 | 2012-8-22 15:09:53 | 显示全部楼层 |阅读模式
试试select * from table1 where (amortize_date, code) in (select code, max(amortize_date) from table 1 group by code);...
回复

使用道具 举报

千问 | 2012-8-22 15:09:53 | 显示全部楼层
select code,max(amortize_date) from table group bycode 我这个是用sqlserver 写的但是我在网上看了一下 postgreSQL 和sqlserver 的基本查询语句好像是一样的...
回复

使用道具 举报

千问 | 2012-8-22 15:09:53 | 显示全部楼层
select * from table where (amortize_date, code) in (select code, max(amortize_date) from table )...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行