简述:写了一个含with子句的SQL,运行没有问题,但是minus另外一个SQL就报错:不支持with子句。请问是不是minus不支持with子句?
如果不支持应该怎么改合适?我的本意是想判断两个查询的结果集是否相等。最好要简单一点通用一点的方法,我想做到任意给我两个查询SQL都可以判断是否结果集相等。
详述:
我的含with子句的SQL是这样的:(2014年创造交易额最多的营业员及其所创造的交易额)
with t as(select userid,sum(dealingprice) sumPrice from SCOTT.dealing where
DEALINGDATE>=to_date('2014-01-01','yyyy-MM-DD') and DEALINGDATE<to_date
('2015-01-01','yyyy-MM-DD') group by userid), tt as (select * from t where
sumPrice=(select max(sumPrice) from t))select
tt.sumprice,SCOTT.userinfo.username from tt,SCOTT.userinfo where
tt.userid=userinfo.userid
单独执行这个with子句并没有错误,是可以的。
但是我minus另外一个SQL就会报错。请问是不是minus不支持with子句?
另外一个SQL是这样的:
select SUM_PRICE, d.username from
(select sum(a.DealingPrice) as sum_price,b.userid as userid1
from scott.Dealing a,scott.Userinfo b
where dealingdate >= to_date('2014-01-01','yyyy-mm-dd') and
dealingdate <= to_date('2014-12-31','yyyy-mm-dd') and
a.UserID = b.UserID
group by b.UserID
order by sum_price desc) c,scott.userinfo d
where rownum = 1 and
c.userid1 = d.userid;