Department table (DEPT)

department employees
The Marketing Department Zhang SAN
The Marketing Department Li si
Sales department Cathy
Sales department Zhao six

Staff Table (EMP)

employees position salary
Zhang SAN sales 1000
Li si The manager 2000
Cathy sales 1500
Zhao six The manager 3000

Write SQL based on the above two tables to query the name of the department whose total salary expenditure is less than 4000.

SELECTDepartment of d.FROM
  dept d, emp e
WHERED. employees=E. employeesGROUP BYDepartment of d.HAVING SUM(e. salary)< = 4000;
Copy the code

Friendship tips: the topic comes from each real enterprise, the above answers are for reference only, can not determine whether to meet the topic to examine the knowledge point!