太难了(对于我来说),请大家帮忙

j99616 2003-08-22 09:20:59
也许大家这样取值很无聊,但我确实需要

是这样的(根据xh排过序的)
id name idr xh
1 aaa 2 1
6 rrr 6 2
4 ttt 6 3
3 uuu 5 4
7 rrr 6 5
2 iii 6 6
我想取第2个idr=6的xh的值
也就是说取第一段连续出现idr=6的组的最后一个记录的值
...全文
25 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nboys 2003-08-22
  • 打赏
  • 举报
回复
try:

select max(xh) from tableName a where exists(select 1 from tableName b where b.xh=a.xh+1 and a.idr=b.idr and b.idr=6)
j99616 2003-08-22
  • 打赏
  • 举报
回复
id name idr xh
1 aaa 2 1
6 rrr 6 2
...........
...........
4 ttt 6 3
3 uuu 5 4
7 rrr 6 5
2 iii 6 6

也许我说的不够清楚,中间的数目不确定
zarge 2003-08-22
  • 打赏
  • 举报
回复
select max(xh) from (select top 2 xh from tab where idr = 6 order by xh) a
愉快的登山者 2003-08-22
  • 打赏
  • 举报
回复
select min(xh) from table1 A where idr = 6
and xh > (select min(xh) from table1 where idr = 6)
CrazyFor 2003-08-22
  • 打赏
  • 举报
回复
select * from 表 aa where (select count(*) from 表 bb where bb.xh=<aa.xh and aa.idr=bb.idr)=2 and aa.idr=6

34,575

社区成员

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

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