SELECT job_id ,Maxsalary,Minsalary FROM employees WHERE commission_pct IS NOT NULL GROUP BY job_id HAVING MAX(salary) AND MIN(salary) > 1054 - Unknown column 'Maxsalary' in 'field list'
时间: 2023-11-28 15:47:09 浏览: 41
这个 SQL 查询语句有一些语法错误。你想查询具有 commission_pct 的职位(job_id),并且这些职位的最高工资(Maxsalary)和最低工资(Minsalary)都大于 1054。下面是一个修改后的查询语句:
```
SELECT job_id, MAX(salary) AS Maxsalary, MIN(salary) AS Minsalary
FROM employees
WHERE commission_pct IS NOT NULL
GROUP BY job_id
HAVING MAX(salary) > 1054 AND MIN(salary) > 1054
```
请注意,我添加了 MAX 和 MIN 函数来计算每个职位的最高工资和最低工资,并将它们作为结果集中的列。然后,我使用 HAVING 语句过滤结果集,只显示符合条件的职位(即最高工资和最低工资都大于 1054)。
相关问题
SELECT job_id ,Maxsalary,Minsalary FROM employees WHERE commission_pct IS NOT NULL GROUP BY job_id HAVING MAX(salary) MIN(salary)
这是一条 SQL 查询语句,用于从 employees 表中获取不为空的 commission_pct 列的所有职位的最高薪资和最低薪资。
但是,该查询语句存在语法错误。正确的语句应该是:
```
SELECT job_id, MAX(salary) AS Maxsalary, MIN(salary) AS Minsalary
FROM employees
WHERE commission_pct IS NOT NULL
GROUP BY job_id
HAVING MAX(salary) IS NOT NULL AND MIN(salary) IS NOT NULL;
```
这样才能正确地按照职位分组,并计算每个组内的最高薪资和最低薪资。同时,HAVING 子句中的条件将确保只返回有薪资信息的职位。
查询工种编号和该工种有提成的员工的工资总和 sum_salary,平均工资 avg_salary,最高工资 max_salary,最低工资 min_salary, 只要 max_salary>6000 的数据,对结果按 max_salary 升序排序
好的,我可以回答这个问题。根据您提供的需求,我可以使用以下 SQL 语句来查询工种编号和该工种有提成的员工的工资总和、平均工资、最高工资、最低工资,并且只返回最高工资大于 6000 的数据。同时,我们也会对结果按照最高工资进行升序排序:
```
SELECT emp.job_id, SUM(emp.salary) AS sum_salary, AVG(emp.salary) AS avg_salary, MAX(emp.salary) AS max_salary, MIN(emp.salary) AS min_salary
FROM employees emp
JOIN jobs job ON emp.job_id = job.job_id
WHERE job.commission_pct IS NOT NULL AND emp.salary > 0 AND emp.salary < 6000
GROUP BY emp.job_id
HAVING MAX(emp.salary) > 6000
ORDER BY MAX(emp.salary) ASC;
```
希望这可以回答您的问题!如果您有任何其他问题,可以随时提出。
阅读全文