string strSql;
strSql = "select user_sep from user_roles where role_num=3 and role_num=7"

解决方案 »

  1.   

    这个是错了,因为没有一行数据可以既为3也为7的,这样将查不出任何数据,也不能用“or”,那样会吧user_seq=2和user_seq=3的记录也查出来,这不是一个简单查询能完成的
      

  2.   

    select * from user_roles where role_num=3
    and user_seq in (
    select user_seq from user_roles where role_num=7)
      

  3.   

    select distinct user_sep from user_roles where role_num=3 and role_num=7
      

  4.   

    select distinct user_sep from user_roles where role_num=3 or role_num=7
      

  5.   

    select distinct user_sep from user_roles 
    where role_num=3 or role_num=7
      

  6.   

    有没有试试我这条,OK的:
    select * from user_roles where role_num=3
    and user_seq in (
    select user_seq from user_roles where role_num=7)
      

  7.   

    select distinct user_sep from user_roles where role_num in (3,7)
      

  8.   

    select * from (select * from user_roles where role_num=7) where role_num=3
      

  9.   

    上面的都不对,我知道这个sql可以工作,但觉得不是标准解决办法:
    select user_seq
    from user_roles
    where role_num = 3 or role_num = 7
    group by user_seq
    having count(*) = 2
      

  10.   

    其中count(*)=2这句中的2意思是一共有2个条件(3和7),如果有三个如:3,7,25的话,这个值应该为3
      

  11.   

    select distinct user_seq from user_rol 
    where role_num=3 
    and user_seq in (select user_seq from user_rol where role_num=7)
    and user_seq not in
    (select distinct user_seq from user_rol where role_num not in (3,7))
      

  12.   

    SELECT *
    FROM (SELECT *
            FROM aa
            WHERE id IN
                      (SELECT id
                     FROM aa
                     GROUP BY id
                     HAVING COUNT(id) > 1)) DERIVEDTBL
    WHERE (a = '3') OR
          (a = '7')
      

  13.   

    select User_Seq from user_roles a 
    where a.role_num = 3 and exists (
    select * from user_roles b where b.User_Seq = a.User_Seq
    and b.role_num = 7)