您可以使用單獨的查詢,如果你想:
select
(select count(*) from employees) Total_Employees,
(select count(*) from employees where country = 'USA') Total_Employees_In_US,
(select sum(bonus) from employees where age < 25) Bonus_OF_Employees_Under_25
from dual
或者在這個例子中,只是一個比較簡單的查詢:
select
count(*) Total_Employees,
sum(case when country = 'USA' then 1 end) Total_Employees_In_US,
sum(case when age < 25 then bonus end) Bonus_OF_Employees_Under_25
from employees
爲了生產組:
select
EmployeeCategory,
count(*) Total_Employees,
sum(case when country = 'USA' then 1 end) Total_Employees_In_US,
sum(case when age < 25 then bonus end) Bonus_OF_Employees_Under_25
from employees
group by EmployeeCategory
我有一個名爲EmployeeCategory的額外列,所有其他列需要在這個上是'Group By'。是否可以調整解決方案來解決這個問題? – Xion 2014-10-21 21:26:59
@Xion是的,你可以做到這一點 - 這是一個簡單的小組,但它只能用第二個版本的查詢。請參閱附錄以回答。 – Bohemian 2014-10-21 22:00:01