您的位置:程序门 -> db2 -> 数据库开发



sql语句,在线等!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


sql语句,在线等![已结贴,结贴人:iriscole]
发表于:2007-04-05 17: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的那一条。
发表于:2007-04-05 17:55:061楼 得分:0
哎,db2会的人咋就那么少呢!
发表于:2007-04-05 20:19:022楼 得分:0
select   *   from   table1   where   substr(速度,1,2)   in  
select   max(substr(速度,1,2))   from   table1
发表于:2007-04-06 10:29:113楼 得分:10
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是很麻烦,上面的能得到你要的.
发表于:2007-04-06 11:11:504楼 得分:10
楼上忘记要写   <=79咯

另外个人觉得使用   (speed-speed/100*100)   要比cast好点吧:)
发表于:2007-04-06 13:47:205楼 得分:0
to   nicole_lixp():
你说的对,用你的,就不需要调用db2的函数进行转化了。
发表于:2007-04-07 08:20:136楼 得分:10
select   *   from   tablename   order   by   mod(speed,100)   desc   fetch   first   rows   only
发表于:2007-04-13 11:11:207楼 得分:20
select   max(mod(速度,100))   from   table   where   mod(速度,100)   between   70   and   79


快速检索

最新资讯
热门点击