如何得到最大的數據?

ZXYSOSO 2004-08-26 03:27:49
ID CODE
1 AAAA HI 1 0 100 2004/07/21
2 AAAA aa 1 1 100 2004/07/22
3 CCCC aa 2 1 100 2004/07/23
4 CCCC aa 2 1 100 2004/07/25
5 DDDD AAD 2 0 100 2004/07/26

以上變化是有規律的,我想得到結果如下,以CODE條件,取得ID為最大的值

2 AAAA aa 1 1 100 2004/07/22
4 CCCC aa 2 1 100 2004/07/25
5 DDDD AAD 2 0 100 2004/07/26
...全文
129 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zsforever 2004-08-26
  • 打赏
  • 举报
回复
select * from yourtable a where id = (select max(id) from yourtable b where b.code=a.code)
ZXYSOSO 2004-08-26
  • 打赏
  • 举报
回复
好,各位,我試下先
panjinfu80 2004-08-26
  • 打赏
  • 举报
回复
select * from 表 where id=(select max(id) as id from 表 where code='@XX')

select * from 表 where id=(select max(id) as id from 表) and code='@XX'
EthanJiang0827 2004-08-26
  • 打赏
  • 举报
回复
select max(id),code from x group by code
yesterday2000 2004-08-26
  • 打赏
  • 举报
回复
select a.* from tb a,(
SELECT MAX(ID) AS ID,CODE FROM tb
group by code) b
where a.id=b.id
pbsql 2004-08-26
  • 打赏
  • 举报
回复
select t.* from t,(select CODE,max(ID) ID from t group by CODE) a
where t.ID=a.ID and t.CODE=a.CODE
hisi 2004-08-26
  • 打赏
  • 举报
回复
select * from 表 where id in ( select max(id) from 表 group by code )

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧