-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');

おそらく、2番目のクエリに状態を含めたいと思うでしょう。

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 に答える