sql语句,在线等!

iriscole 2007-04-05 05:14:58
No 速度 值
1 171 1000
2 151 999
3 161 998
4 162 997
5 163 1000
6 175 999
7 159 1000

速度都是三位smallint,怎么查出速度后两位在70~79之间的最大值?
也就是No=6的那一条。
...全文
249 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
FlyFreeBird 2007-04-13
  • 打赏
  • 举报
回复
select max(mod(速度,100)) from table where mod(速度,100) between 70 and 79
songfrh 2007-04-07
  • 打赏
  • 举报
回复
select * from tablename order by mod(speed,100) desc fetch first rows only
nicole_lixp 2007-04-06
  • 打赏
  • 举报
回复
楼上忘记要写 <=79咯

另外个人觉得使用 (speed-speed/100*100) 要比CAST好点吧:)
yangxiao_jiang 2007-04-06
  • 打赏
  • 举报
回复
select * from table2 where cast(SUBSTR(char(speed),2,2) as integer) in
(select max(cast(SUBSTR(char(speed),2,2) as integer)) as t from table2 where cast(SUBSTR(char(speed),2,2) as integer) >70 and cast(SUBSTR(char(speed),2,2) as integer)<79)


db2是很麻烦,上面的能得到你要的.
yangxiao_jiang 2007-04-06
  • 打赏
  • 举报
回复
to nicole_lixp():
你说的对,用你的,就不需要调用db2的函数进行转化了。
lsj19830812 2007-04-05
  • 打赏
  • 举报
回复
select * from table1 where SUBSTR(速度,1,2) in
select max(SUBSTR(速度,1,2)) from table1
iriscole 2007-04-05
  • 打赏
  • 举报
回复
哎,db2会的人咋就那么少呢!

5,889

社区成员

发帖
与我相关
我的任务
社区描述
IBM DB2 是美国IBM公司开发的一套关系型数据库管理系统,它主要的运行环境为UNIX(包括IBM自家的AIX)、Linux、IBM i(旧称OS/400)、z/OS,以及Windows服务器版本
社区管理员
  • DB2
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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