查询-Sql 开发者

Query-Sql Developer

我正在为我的项目创建一些查询,但我遇到了以下问题:

一个 SELECT 语句包含一个子查询,用于检索位置列表(位置 ID 和 street_address),这些位置的员工薪水高于其部门的平均水平。该列表必须包含这些员工的数量以及他们在每个地点的总工资。分别将这些聚合命名为 "emp" 和 "totalsalary"。列表中的位置必须按 location_id.

排序
Select LOCATION_ID, STREET_ADDRESS
from HR.LOCATIONS IN
(Select Employee_id
from HR.Employees
Where Salary > round(avg(SALARY)))
order by location_id; 

error: SQL command not properly ended

第二个查询如下

JOB_HISTORY table 可以包含多次雇用的员工的多个条目。创建一个查询以检索被多次雇用的员工列表。包括列 EMPLOYEE_ID、LAST_NAME、FIRST_NAME 和聚合 "Times Hired".

SELECT FIRST_NAME,LAST_NAME,EMPLOYEE_ID, 
count (*)as TIMES_HIRED 
from HR.JOB_HISTORY, HR.EMPLOYEES 
where EMPLOYEE_ID= LAST_NAME 
having COUNT(*) >1; 
error: not a single-group

尝试这些希望它们有所帮助。我假设员工 table 有 Location_Id 列。我将 Employee_id 添加到分组依据以确保您得到正确的 TotalSalary:

Select LOCATION_ID, STREET_ADDRESS, Count(Employee_id) AS emp, SUM(salary) AS totalsalary
from HR.LOCATIONS INNER JOIN
(Select Employee_id, salary
from HR.Employees
Having Salary > round(avg(SALARY), 0)) AS Emp ON HR.LOCATION_ID = Emp.Location_ID
Group By LOCATION_ID, STREET_ADDRESS, Employee_id
order by location_id; 

第二个问题:

SELECT FIRST_NAME,LAST_NAME,EMPLOYEE_ID, 
count(Employee_id) as TIMES_HIRED 
from HR.JOB_HISTORY inner join HR.EMPLOYEES On JOB_HISTORY.Employee_id = Employees.Employee_id
Group By FIRST_NAME,LAST_NAME,EMPLOYEE_ID
Having count(Employee_id) >1;