在Oracle Sql中添加count的结果

时间:2013-06-17 22:22:05

标签: sql

我正在尝试这两个表的元素数量是我尝试过的:

 select 
((select count(*) from Person,Professor where ID_Person = ID_Professor)  + 
(select count(*) from Person, Student where ID_Person = ID_Student ))

这不起作用任何想法我怎么能这样做? 提前谢谢

2 个答案:

答案 0 :(得分:1)

你最后错过了一个from dual,让外部选择一个完整的陈述。

正如你所说的那样加上from dual

select 
((select count(*) from Person,Professor where ID_Person = ID_Professor)  + 
(select count(*) from Person, Student where ID_Person = ID_Student ))
from dual

答案 1 :(得分:1)

Wumpus Q. Wumbley对Oracle数据库给出了正确的建议。

对于您的问题,您也可以尝试以下查询 -

   select sum(c_total) 
    from (
      select (select count(*) from professor 
               where professor.id_professor=person.id_person)
           + (select count(*) from student 
               where student.id_student=person.id_person) c_total
      from person
     group by person.id_person)