业务表A
字段1 用户名
字段二 业务名称如何查出所有包含业务A和业务B的用户.
字段1 用户名
字段二 业务名称如何查出所有包含业务A和业务B的用户.
解决方案 »
- 关于海量数据求最晚时间的问题
- oracle 10g 导入数据库后,如何创建用户,并且能查看该数据库。
- 用utl_file导出excel
- ********求一存储过程或函数将用户传的语句转换为ORACLE语句***********
- oracle 临时表的数据是放在内存,还是放在硬盘上?
- 小弟跪求!想导出oracle中一个表的部分列,请高手们帮忙啊
- 一个关于case的简单问题,大家帮帮忙
- 联接ORACLE的疑问?不用指定数据源吗?
- oracle的VARCHAR2类型的奇怪现象
- 在oracle中怎样算出两个时刻的时间间隔,以小时,分计
- sqlplus 突然僵死,一直处于等待状态,无报错信息。
- oracle 什么是数据仓库
--或者
select 用户名 from a where 业务名称='业务A' or 业务名称='业务B';
select 用户名 from a where 业务名称='业务A'
UION
select 用户名 from a where 业务名称='业务B'
select 用户名 from a where 业务名称='业务A'
union
select 用户名 from a where 业务名称='业务B'
是如何查出所有既包含业务A又业务B的用户
[/Quote]--那就用and
select 用户名 from a where 业务名称='业务A' and 业务名称='业务B';
--建议你要先熟悉下sql 这个应该是初级题吧
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.用户名称)
--那就用and
select 用户名 from a where 业务名称='业务A' and 业务名称='业务B';
--建议你要先熟悉下sql 这个应该是初级题吧
[/Quote]还是去学习一下吧,你看看你的这个能查出来不.
业务表A
字段1 用户名
字段二 业务名称如何查出所有包含业务A和业务B的用户.
一楼的方法应该可以实现
select a.用户名称 from table a
where
exists(select 'x' from table b where b.用户名称=a.用户名称 and b.业务名称='业务a')
and a.业务名称='业务b'
--table
create table test(
用户名 varchar(20),
业务名称 varchar(20));
--sql statements
select 用户名 from test where 业务名称 in ('业务A','业务B');
select 用户名 from test where 业务名称='业务A' and 业务名称='业务B';
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
where a.字段1= b.字段1
and a.字段二 = '业务A'
and b.字段二 = '业务B'
WHERE ee.字段二='业务二' AND ee.字段一 IN
(SELECT e.字段一 FROM tableA e WHERE e.字段二='业务一')
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 );
(select 用户名 from 业务表a where 业务名称='业务a') a,
(select 用户名 from 业务表a where 业务名称='业务b') b
where a.用户名=b.用户名