SQL查找子查询

时间:2017-04-27 18:59:59

标签: mysql sql

我有一张工资表,我必须找到零的平均值与零之间的差异,所以这是我的查询

SELECT ((SELECT REPLACE(Salary, '0', '') FROM TEST) - (SELECT ROUND(SUM(Salary)/COUNT(*)) FROM Test)) FROM Test

不幸的是我的查询无效。 示例5工资:5049,7000,2000,3900
我必须找到5049,7000,2000,3900549,7,2,39

的平均值

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT a.without, a.with, a.with - a.without
FROM(
  SELECT AVG(CAST(REPLACE(Salary, '0', '') AS INT)) AS 'without', AVG(salary) 
  as 'with'
  FROM test) a