[英]SQL error in Oracle?
我正在尝试获取SQL Oracle中count列的总数,但我不断收到THE错误:
ORA-00907 missing the right parenthesis
谁能帮我解决此错误?
这是我的查询:
select isnull(s.years, 'Total') as Grade, count(*) as cnt1, c.firstname, c.lastname
from(
Select s.years, SUM(count(*) as cnt1), c.firstname, c.lastname
from employees cc
inner join building1 c on cc.id = c.bldid
inner join members s on s.id = cc.id
where sec.LastName = 'Cook'
group by s.years WITH ROLLUP, c.firstname, c.lastname
order by s.years, c.firstname, c.lastname
) as cnt
select isnull(cnt.years, 'Total') Grade, count(*) as cnt1, cnt.firstname, cnt.lastname
from(
Select s.years, SUM(count(*)) as cnt1, c.firstname, c.lastname
from employees cc
inner join building1 c on cc.id = c.bldid
inner join members s on s.id = cc.id
where sec.LastName = 'Cook'
group by s.years WITH ROLLUP, c.firstname, c.lastname
order by s.years, c.firstname, c.lastname
) cnt --you have to use this to reference columns in the outer query
您正在从名为cnt
的内部查询中进行选择。 您应该使用它来引用外部查询中的列。
C。 必须用cnt代替。
在ORACLE中,您不能使用ISNULL,使用COALESCE并删除SUM中的别名。
SELECT coalesce(s.years, 'Total') AS Grade, count(*) AS cnt1, c.firstname, c.lastname
FROM (SELECT s.years, SUM(count(*)) AS cnt1, c.firstname, c.lastname
FROM employees cc
INNER JOIN building1 c on cc.id = c.bldid
INNER JOIN members s on s.id = cc.id
WHEREsec.LastName = 'Cook'
group by s.years WITH ROLLUP, c.firstname, c.lastname
order by s.years, c.firstname, c.lastname
) as cnt
从SUM
内部删除您的别名。
SELECT isnull(s.years, 'Total') AS Grade, count(*) AS cnt1, c.firstname, c.lastname
FROM (SELECT s.years, SUM(count(*)) AS cnt1, c.firstname, c.lastname
FROM employees cc
INNER JOIN building1 c ON cc.id = c.bldid
INNER JOIN members s ON s.id = cc.id
WHERE sec.LastName = 'Cook'
GROUP BY s.years WITH ROLLUP, c.firstname, c.lastname
ORDER BY s.years, c.firstname, c.lastname) AS cnt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.