读书人

oracle 数据库中怎么实现上面的查询啊

发布时间: 2013-01-18 10:22:42 作者: rapoo

oracle 数据库中如何实现下面的查询啊!!
假如我有一张表 表名为 u 此表中有以下字段 id(自增长),wid(告警ID),Uid(用户ID),dt(开始时间),enddt(结束时间)

wid,uid都是整型的,存在另外一张表,现在用户uid=(277,278,288,299...n),wid=(1,2,3,4,5....n)[这个长度是有限的]
现在有这样的需求

用过用户ID,告警ID,开始时间与结束时间查询出数据来,告警ID的条件不是wid in (1,2,3,4,5,....n) 而是说某个用户他的即包含wid=1又要包含wid=2的才允许查出来信息,应该怎么样写查询语句? '


with tmp_table as
(select wid from u t2 where t2.uid = 用户1)

select * from u t1
where t1.uid = 用户1
and not exists (
select 1 from
(
select regexp_substr(警告号,'[^,]+',1,level) wid from dual connect by level<=
(select length(警告号)-length(replace(警告号,',')) from dual)+1
) t4
where not exists ( select 1 from tmp_table t5 where t5.wid=t4.wid )
);

读书人网 >oracle

热点推荐