我创建了一个物化视图,但我有一个错误,我不明白解决它
SELECT x.*,SUM(x.quantities) as Tquantities
在线
CREATE MATERIALIZED VIEW TestView AS
With x AS(
SELECT Numclient as CLIENT,
Numcommand as COMMAND,
count(gender) as quantities
FROM customer,
Command
WHERE Numclient = Numcommand
AND gender =2
GROUP BY Numclient,
Numcommand
),
x1 AS (
SELECT x.*,SUM(x.quantities) as Tquantities
FROM x
)
SELECT x.*,ROUND(x.quantities*100/x1.Tquantities) as Percent
FROM x1, x;
你能帮我解决吗?
j_query data_tables
答案 0 :(得分:1)
为了消除错误,请删除原始子查询x.*,
中的x1
。
您的select
语句可以简化,例如:
select Numclient CLIENT, Numcommand COMMAND, count(gender) quantities,
round(100*count(gender)/sum(count(gender)) over()) percent
from customer
join Command on Numclient = Numcommand and gender = 2
group by Numclient, Numcommand
有点不清楚为什么你显示列COMMAND,当它等于CLIENT?
我怀疑这可能是where
条件中的错误,或者此列是多余的。
答案 1 :(得分:0)
从什么时候开始在Oracle中有效?这不是MySQL。
SELECT x.*,SUM(x.quantities) as Tquantities FROM x
为了使其正常工作,您必须对X中的列进行GROUP BY。