我有一个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
答案 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 ...