为我的简单问题道歉,我是一个绝对的新手。我在separate queries
中有以下代码我试图显示3列,设定工作的平均男性工资,设定工作的平均女性工资和工作ID。另外这些查询工作,但我无法弄清楚如何组合它们。 我尝试过此网站的多个解决方案,例如trying to put multiple select statements inside 并且通过使用'union'解决方案然而无法工作。union这只是将它们编译成一个列并通过工资而不是JobID进行排序。
SELECT Round(Avg(Salary)) AS AverageMaleSalary, JobID
FROM Employee WHERE Gender = "M"
GROUP BY JobID;
SELECT Round(Avg(Salary)) AS AverageFemaleSalary, JobID
FROM Employee WHERE Gender = "F"
GROUP BY JobID;
答案 0 :(得分:1)
您可以使用条件聚合
SELECT JobId,ROUND(AVG(IIF(Gender='F', Salary, NULL))) AS AverageFemaleSalary
,ROUND(AVG(IIF(Gender='M', Salary, NULL))) AS AverageMaleSalary
FROM Employee
GROUP BY JobId;