这个表一个字段是varchar的
值是:
10-12
13-18
19-28
29-30像这样的无规则的一组数值范围,应该用一句SQL怎么查出呢?例如我要查出15这个值在那个范围?用like好像不行。请高手指点。谢谢

解决方案 »

  1.   

    select 
      *
    from 
      tb
    where 
      15 
    between 
      left(字段,LOCATE('-',字段)-1)+0 
    and 
      SUBSTRING(字段,LOCATE('-',字段)+1,LENGTH(字段)-LOCATE('-',字段))+0;
      

  2.   

    select col
    from yourTable
    where col<='15'
    order by col desc
    limit 1;
      

  3.   

    create table tb(col varchar(100));
    insert tb
    select '10-12' union all 
    select '13-18' union all  
    select '19-28' union all  
    select '29-30'  select 
      *
    from 
      tb
    where 
      15 
    between 
      left(col,LOCATE('-',col)-1)+0 
    and 
      SUBSTRING(col,LOCATE('-',col)+1,LENGTH(col)-LOCATE('-',col))+0;/**结果col           
    13-18     **/  
      

  4.   

    select * from tt3 where 
    mid(gg,1,instr(gg,'-')-1)<'15'
    and 
    mid(gg,instr(gg,'-')+1)>'15'orselect * from tt3 where 
    0+mid(gg,1,instr(gg,'-')-1)<15
    and 
    0+mid(gg,instr(gg,'-')+1)>15
      

  5.   

    兄弟们知道用Hibernate怎么实现这个查询吗?