我可以 select SQL 中的一组平均值吗
Can I select a set of averages in SQL
我可以 select 一组基于 SQL 字段的平均值吗?
类似于:
SELECT
AVG(Salary WHERE department = 1) as AvgDept1,
AVG(Salary WHERE title = 1) as AvgTitle1,
AVG(TimeOnJob WHERE title = 1 and department = 1) as AvgTime1
FROM
Employees
我知道这类似于带有 GROUP BY 的 AVG,但我不知道如何从中获取三个值。
这些看起来像三个独立的查询,
如果你想把它们捆绑成一个 select 你可以这样做:
SELECT
(SELECT AVG(Salary) WHERE department = 1 FROM Employees) AS AvgDept1,
(SELECT AVG(Salary) WHERE title = 1 FROM Employees) AS AvgTitle1
(select AVG(TimeOnJob) WHERE title = 1 and department = 1 FROM Employees) AS AvgTime1
我可以 select 一组基于 SQL 字段的平均值吗? 类似于:
SELECT
AVG(Salary WHERE department = 1) as AvgDept1,
AVG(Salary WHERE title = 1) as AvgTitle1,
AVG(TimeOnJob WHERE title = 1 and department = 1) as AvgTime1
FROM
Employees
我知道这类似于带有 GROUP BY 的 AVG,但我不知道如何从中获取三个值。
这些看起来像三个独立的查询, 如果你想把它们捆绑成一个 select 你可以这样做:
SELECT
(SELECT AVG(Salary) WHERE department = 1 FROM Employees) AS AvgDept1,
(SELECT AVG(Salary) WHERE title = 1 FROM Employees) AS AvgTitle1
(select AVG(TimeOnJob) WHERE title = 1 and department = 1 FROM Employees) AS AvgTime1