select a.id,a.uid,a.xianlu,a.pbqd from zd_base a,zd_base b where a.uid!=b.uid and a.xianlu=b.xianlu and find_in_set('幸福站',a.pbqd) group by a.id having count(1)>0查询结果如下图 
需要实现的是   1 a.uid!=b.uid 2 a.xianlu=b.xianlu3 关键词 find_in_set('幸福站',a.pbqd) 以上3个 任何一个条件不满足都不显示  三个都满足一起显示

解决方案 »

  1.   

    按照楼主的条件搜索出这些数据没问题,另外group by那块写的有问题,只是没有报错。
    建议楼主给出测试数据和想要的对应结果。
      

  2.   

    按照楼主的条件搜索出这些数据没问题,另外group by那块写的有问题,只是没有报错。
    建议楼主给出测试数据和想要的对应结果。a.uid != b.uid 仔细看第一个条件应该不满足的 但是还是被搜索出来了  
      

  3.   

    按照楼主的条件搜索出这些数据没问题,另外group by那块写的有问题,只是没有报错。
    建议楼主给出测试数据和想要的对应结果。a.uid != b.uid 仔细看第一个条件应该不满足的 但是还是被搜索出来了  
    可以有满足的,
    比如 
    uid xianlu
    1 章西线
    2 章西线a.uid != b.uid 是能搜出来结果的
      

  4.   

    你的语句, 写这样更容易理解:
    SELECT a.id,
           a.uid,
           a.xianlu,
           a.pbqd
    FROM   zd_base     a
    WHERE 
    find_in_set('幸福站', a.pbqd)
    AND EXISTS(
    SELECT 1 
    FROM  zd_base b
    WHERE  a.uid != b.uid
       AND a.xianlu = b.xianlu
    )显示出来的, 跟你比较的根本不是一个东西。
      

  5.   


    查询出来还是一样的效果 a.uid != b.uid 但是 还是查询出来 两条用一uid的数据  所有不成立
      

  6.   

    楼主你这样写得到的数据没有问题,楼主可以这样看一下得到的数据是什么,就是可能不是你想要的
    select a.id,a.uid,a.xianlu,a.pbqd,b.id,b.uid,b.xianlu,b.pbqd from zd_base a,zd_base b where a.uid!=b.uid and a.xianlu=b.xianlu and find_in_set('幸福站',a.pbqd) group by a.id having count(1)>0楼主你可以描述一下你想要的是什么,给出测试数据和想要的结果,直接帮你写语句
      

  7.   


    同一张表  如下id  uid    xianlu   pbqd 
    1     1      1           1,2,3,4,5,6
    2     1      3           10,11,12,13 
    3     1      2           14,12,16,19
    4     1      4           13,21,23,24,46,65
    5     1      6           23,30,22,38,47,
    6     2      1           70,71,72,73,6
    7     2      7           74,75,76,77,78,79
    8     2      11           81,82,83,84,85
    9     2      8           86,87,88,89
    10   2      9           90,91,92,93,94需要找出   主要以 pbqd 这个字段里的  6 来查询  uid不能相同  xianlu相同的条数  以上符合条件 只有1和6  
      

  8.   

    我用mssql写的,楼主看一下
    --测试数据
    if not object_id(N'Tempdb..#T') is null
    drop table #T
    Go
    Create table #T([id] int,[uid] int,[xianlu] int,[pbqd] nvarchar(37))
    Insert #T
    select 1,1,1,N'1,2,3,4,5,6' union all
    select 2,1,3,N'10,11,12,13' union all
    select 3,1,2,N'14,12,16,19' union all
    select 4,1,4,N'13,21,23,24,46,65' union all
    select 5,1,6,N'23,30,22,38,47,' union all
    select 6,2,1,N'70,71,72,73,6' union all
    select 7,2,7,N'74,75,76,77,78,79' union all
    select 8,2,11,N'81,82,83,84,85' union all
    select 9,2,8,N'86,87,88,89' union all
    select 10,2,9,N'90,91,92,93,94'
    Go
    --测试数据结束
    SELECT a.*
    FROM #T a
        JOIN #T b
            ON b.uid <> a.uid
               AND b.xianlu = a.xianlu
               AND a.pbqd LIKE '%6%'
               AND b.pbqd LIKE '%6%';