django 实现根据状态统计数据
原生 SQL
SELECT
SUM(
CASE WHEN order_status = 4 THEN deposit_amt - refund_amt + final_amt
WHEN order_status = 7 THEN deposit_amt
WHEN order_status = 0 THEN deposit_amt
ELSE 0
END
)
FROM "order" WHERE deleted_at = 0 AND cancelled = FALSE AND boat_type=1;
Djiango
hire = hire.aggregate(
sum=Sum(
Case(
When(order_status=4, then=F('deposit_amt') - F('refund_amt') + F('final_amt')),
When(Q(order_status=7) | Q(order_status=0), then=F('deposit_amt')),
default=0
)
)
)
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17789702.html