具有两个条件的SQL查询

时间:2018-10-18 03:08:07

标签: sql sql-server subquery

我是SQL查询的新手,所以在进行查询时遇到了一些问题。我正在使用SQL Server Management Studio。

我的任务是选择平均工资+佣金低于2500的地区部门部门。

我的SQL语句:

select regional_group 
from LOCATION 
join DEPARTMENT on location.location_id = DEPARTMENT.location_id 
join EMPLOYEE on DEPARTMENT.department_id = EMPLOYEE.department_id 
where EMPLOYEE.department_id in (select avg(salary + commission) 
                                 from employee)

Structure of the database enter image description here

2 个答案:

答案 0 :(得分:2)

您必须在内部查询的where子句中放置条件

select regional_group 
from LOCATION 
join DEPARTMENT on location.location_id = DEPARTMENT.location_id 
join EMPLOYEE on DEPARTMENT.department_id = EMPLOYEE.department_id 
where EMPLOYEE.department_id in (select department_id 
                                 from employee 
                                 where salary + commission < 2500)

答案 1 :(得分:0)

SQL查询

Select L.Reginal_group
From Employee E
Join Department D ON
D.Department_id = E.Department_id
Join Location L ON
D.Location_id = L.Location_id
WHERE avg(E.salary+E.commission) < 2500