-1

我有如下所示的表格。员工表

Date        Employee ID   Employer ID     Salary
2/3/2011      10            20            45666
3/12/2009     43            53            2356

雇主表

Employer ID     State
53                OH
42                MI  

尝试使用 group by 子句按月和按州获得总工资。但没有得到结果。我究竟做错了什么??任何帮助表示赞赏

select date, sum(salary) from employee
group by to_char(date,'MON')

select sum(salary) from employee A, Employer B
where A.employer id=B.employer id
group by B.state

我还需要根据他们的薪水获得前 10 名不同的员工 ID

select DISTINCT employee id from employee
where rownum<=10
order by salary desc
4

1 回答 1

2

您必须按选择列表中的确切表达式进行分组,例如,

select to_char(date,'MON'), sum(salary) 
  from employee 
 group by to_char(date,'MON');

您可能希望在第二个查询中包含状态:

select b.state, sum(salary) 
  from employee A, Employer B  
 where A.employer_id=B.employer_id  
 group by B.state;

一般来说,在你的问题中说你“没有得到结果”对你寻求帮助的人来说并不是很有帮助。请提供描述“未获得结果”含义的任何错误消息或输出。

于 2012-09-11T16:27:21.113 回答