业务表A
字段1  用户名
字段二  业务名称如何查出所有包含业务A和业务B的用户.

解决方案 »

  1.   

    select 用户名 from a where 业务名称 in ('业务A','业务B');
    --或者
    select 用户名 from a where 业务名称='业务A' or 业务名称='业务B';
      

  2.   

    select 用户名 from a where 业务名称='业务A' or 业务名称='业务B';
      

  3.   


    select 用户名 from a where 业务名称='业务A' 
    UION
    select 用户名 from a where 业务名称='业务B' 
      

  4.   


    select 用户名 from a where 业务名称='业务A' 
    union
    select 用户名 from a where 业务名称='业务B' 
      

  5.   

    Quote=引用 5 楼 renciabc 的回复:]
    是如何查出所有既包含业务A又业务B的用户
    [/Quote]--那就用and
    select 用户名 from a where 业务名称='业务A' and 业务名称='业务B';
    --建议你要先熟悉下sql 这个应该是初级题吧
      

  6.   

    select * from table where 字段一 in (select 字段一 from table where 字段二='业务A') and 字段二='业务b'
      

  7.   


    select distinct 用户名称 from table a where
    exists(select 1 from table where 业务名称='业务a' and 用户名称=a.用户名称)
    and 
    exists(select 1 from table where 业务名称='业务b' and 用户名称=a.用户名称)
      

  8.   

    SQL code
    --那就用and
    select 用户名 from a where 业务名称='业务A' and 业务名称='业务B';
    --建议你要先熟悉下sql 这个应该是初级题吧
    [/Quote]还是去学习一下吧,你看看你的这个能查出来不.
      

  9.   

    [Quote=引用楼主 renciabc 的回复:]
    业务表A
    字段1  用户名
    字段二  业务名称如何查出所有包含业务A和业务B的用户.
    一楼的方法应该可以实现
      

  10.   

    select distinct 用户名 from a where 业务名称 in ('业务A','业务B');
      

  11.   


    select a.用户名称 from table a 
    where
    exists(select 'x' from table b where b.用户名称=a.用户名称 and b.业务名称='业务a')
    and a.业务名称='业务b'
      

  12.   


    --table
    create table test(
    用户名 varchar(20),
    业务名称 varchar(20));
    --sql statements
    select 用户名 from test where 业务名称 in ('业务A','业务B');
    select 用户名 from test where 业务名称='业务A' and 业务名称='业务B';
      

  13.   


    select 用户名 from tb 
    where 业务名称 in('业务A','业务B') group by 用户名 
    having count(1)=2--例子
    SQL> edi
    已写入 file afiedt.buf  1  with tb as
      2  (select 'wkc168' username,'a' ywmc from dual
      3  union all
      4  select 'wkc168','b' from dual
      5  union all
      6  select 'wkc28','a' from dual
      7  union all
      8  select 'wkc28','b' from dual
      9  union all
     10  select 'wkc1','a' from dual
     11  union all
     12  select 'wkc2','b' from dual
     13  union all
     14  select 'wkc3','c' from dual)
     15  select username from tb
     16  where ywmc in('a','b')
     17  group by username
     18* having count(1)=2
    SQL> /USERNA
    ------
    wkc168
    wkc28
      

  14.   

    select a.* from 业务表A a,业务表A b
    where a.字段1= b.字段1
    and a.字段二 = '业务A'
    and b.字段二 = '业务B'
      

  15.   

    SELECT * FROM tableA ee WHERE ee.字段二='业务二' AND ee.字段一 IN (SELECT e.字段一 FROM tableA e WHERE e.字段二='业务一')
      

  16.   

    SELECT * FROM tableA ee 
    WHERE ee.字段二='业务二' AND ee.字段一 IN 
    (SELECT e.字段一 FROM tableA e WHERE e.字段二='业务一')
      

  17.   

    CREATE TABLE t(
    username VARCHAR2(20), -- 用户名
    opname VARCHAR2(20)    -- 业务名
    );SELECT distinct t1.username
    FROM t t1
    WHERE EXISTS(SELECT 1
                 FROM t t2
                 WHERE (t2.opname='A' OR t2.opname='B')
                 AND t2.username=t1.username
                 GROUP BY t2.username
                 HAVING COUNT(DISTINCT opname)=2 );
      

  18.   

    select 用户名 from 
       (select 用户名 from 业务表a where 业务名称='业务a') a,
       (select 用户名 from 业务表a where 业务名称='业务b') b
    where a.用户名=b.用户名