比如這里我需要判斷時間>0時計算所有得去重后的id的總和
這一行:
count(distinct(case when (t.pay_time > 0) then t.user_id else null end)) AS buyerQuality
完整代碼:
async rechargeSum(time) {
// orderSumQuality是所有的訂單數(包括已支付和未支付)
return await this.app.model.query(
`select count(1) 'orderSumQuality',
IFNULL(sum(case when t.pay_time > 0 then 1 else 0 end), 0) AS orderQuality,
IFNULL(sum(case when t.pay_time > 0 then t.income else 0 end), 0) AS realGoldCoin,
IFNULL(sum(case when t.pay_time > 0 then t.extra_income else 0 end), 0) AS presentGoldCoin,
IFNULL(sum(case when t.pay_time > 0 then t.order_amount else 0 end), 0) AS orderTotolSum,
IFNULL(sum(case when t.pay_time > 0 then t.amount else 0 end), 0) AS amountReceived,
count(distinct(case when (t.pay_time > 0) then t.user_id else null end)) AS buyerQuality
FROM hx_user_recharge_record AS t ${time}`,
{ type: 'SELECT' })
}