将2个sql查询加入其中

时间:2014-09-01 13:08:18

标签: mysql

我有一个MySQL查询:

SELECT *, if (closeddate is null, 1, 2) as STATUS
FROM loanproc

我希望能够创建以下两个字段,这些字段将利用所有记录来生成整体统计信息的结果值。

SELECT Avg((legalrecv - legalordered)) as avgLegal, Avg((appraisalrecv - appraisalordered)) as  AvgAppraise
FROM loanproc

1 个答案:

答案 0 :(得分:0)

这样的东西?

SELECT Avg((legalrecv - legalordered)) as avgLegal, Avg((appraisalrecv - appraisalordered)) as  AvgAppraise, Status
FROM 
  ( SELECT *, if (closeddate is null, 1, 2) as STATUS
    FROM loanproc ) T
Group by ...