结构:
table1有两个字段,
分别是aggrid和idvalue,都是字符字段,
里面的内容都是用,号分隔的三个数字,并且是一一对应的,
比如aggrid内容是:26,59,6
idvalue内容是:1502.5,1690,2276.77
一一对应就是26的值是1502.5,59是1690,6对应2276.77搜索条件:
选择一个id,比如选择59,再输入一个数字,比如:2000
然后就是搜索aggrid中存在id=59的记录,然后搜索idvalue小于2000,即1690<2000举例:
如有以下三条记录,搜索id为59,值小于2000的记录:
26,59,6 | 1502.5,1690,2276.77
59,33,6 | 3502.1,1020,2276.77
22,8,59 | 1332.6,2900,1520.77搜索到这三个记录存在id为59,之后判断第二个搜索条件应为(即用对应id位置的数字对比):
1690<2000
3502.1<2000
1520.77<2000====
我想了很久没想出,求解sql,谢谢大家

解决方案 »

  1.   

    BILLSSJONE (BILLSSJONE)
      '截至2010-08-01 14:50:10  用户结帖率33.14%  总发帖:175  正常结帖:58  未结帖:117  当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  2.   

    select * from (
    select SUBSTRING_INDEX(aggrid,',',1) a,SUBSTRING_INDEX(idvalue,',',1) b
    from table1
    union all
    select SUBSTRING_INDEX(SUBSTRING_INDEX(aggrid,',',2),',',-1),SUBSTRING_INDEX(SUBSTRING_INDEX(idvalue,',',2),',',-1)
    from table1
    union all
    select SUBSTRING_INDEX(aggrid,',',-1),SUBSTRING_INDEX(idvalue,',',-1),
    from table1
    ) t
    where a=59 and b<2000
      

  3.   

    谢谢,太酷了,测试通过,
    SUBSTRING_INDEX(idvalue,',',-1),
    有一个小地方的书写错误,最后这个后面要去掉,号
    还有就是a=59 and b<2000改成t.a=59 and t.b<2000
    马上把所有的帖结了。
      

  4.   

    select col1,col2
    from (select *,find_in_set('59',col1) as rn from ji) k
    where reverse(left( reverse(concat(',',substring_index(col2,',',rn))),
    locate(',',reverse(concat(',',substring_index(col2,',',rn))))-1)) <'2000';
      

  5.   

    找到一个更加简单到写法
    select col1,col2
    from (select *,find_in_set('59',col1) as rn from ji) k
    where substring_index(concat(',',substring_index(col2,',',rn)),',',-1)
     <'2000';
      

  6.   

    feixianxxx两个都不灵光啊,都是出来所有的记录,跟没搜索一样,我这里真实输出的sql是如下,出来所有记录:
    select * from (select *,find_in_set('30303',school_cCity) as rn from school_school) A where substring_index(concat(',',substring_index(A.school_cDistance,',',rn)),',',-1)<'50000'; 
      

  7.   


    那你改成 
    select col1,col2
    from (select *,find_in_set('59',col1) as rn from ji) k
    where cast(substring_index(concat(',',substring_index(col2,',',rn)),',',-1) as int) <2000;
      

  8.   

    输出:
    select * from (select *,find_in_set('89111',school_cCity) as rn from school_school) A where cast(substring_index(concat(',',substring_index(A.school_cDistance,',',rn)),',',-1) as int)<25000; 出错:
    Mysql error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)<25000' at line 3