Sql 从oracle中的子查询给定错误
我有这样的疑问:Sql 从oracle中的子查询给定错误,sql,database,oracle,oracle11g,Sql,Database,Oracle,Oracle11g,我有这样的疑问: SELECT T.custno,T.custlastname,AVG(T.OrderAmount) , T.OrderCount FROM( SELECT A.custno,A.custlastname,count(b.ordno) as OrderCount, sum(c.qty*d.prodprice) AS OrderAmount FROM customer A JOIN ordertbl B ON A.custno=b.custn
SELECT T.custno,T.custlastname,AVG(T.OrderAmount) , T.OrderCount
FROM(
SELECT A.custno,A.custlastname,count(b.ordno) as OrderCount, sum(c.qty*d.prodprice) AS OrderAmount
FROM customer A
JOIN ordertbl B ON A.custno=b.custno
JOIN ordline C ON b.ordno=c.ordno
JOIN product D ON c.prodno=d.prodno
WHERE A.custstate='CO'
GROUP BY A.custno,A.custlastname, b.ordno) AS T
GROUP BY T.custno,T.custlastname;
我得到这个错误:
ORA-00933: SQL command not properly ended
当我显式执行内部子查询时,它运行良好。请告诉我原因
你可以试试我猜你在外部查询的
GROUPBY
子句中缺少一列。尝试下面的查询
SELECT T.custno,T.custlastname,AVG(T.OrderAmount) , T.OrderCount
FROM (SELECT A.custno,
A.custlastname,
count(b.ordno) as OrderCount,
sum(c.qty*d.prodprice) AS OrderAmount
FROM customer A
JOIN ordertbl B ON A.custno=b.custno
JOIN ordline C ON b.ordno=c.ordno
JOIN product D ON c.prodno=d.prodno
WHERE A.custstate='CO'
GROUP BY A.custno,A.custlastname, b.ordno) T
GROUP BY T.custno,T.custlastname,T.OrderCount;
试试这个:
SELECT T.custno,T.custlastname,avg(T.OrderAmount) , T.OrderCount
FROM (SELECT A.custno,
A.custlastname,
count(b.ordno) as OrderCount,
sum(c.qty*d.prodprice) AS OrderAmount
FROM customer A
JOIN ordertbl b ON A.custno=b.custno
JOIN ordline c ON b.ordno=c.ordno
JOIN product d ON c.prodno=d.prodno
WHERE A.custstate='CO'
GROUP BY A.custno,A.custlastname,b.ordno,OrderAmount,
OrderCount) AS T)
GROUP BY T.custno,T.custlastname,T.OrderAmount,T.OrderCount;
不,还是一样的结果:(