,SUM(CASE `支付状态` WHEN 2 THEN 1 ELSE 0 END)
,SUM(CASE `支付状态` WHEN 1 THEN `支付金额` ELSE 0 END)
,SUM(CASE `支付状态` WHEN 1 THEN 1 ELSE 0 END)
FROM `订单`
这个SQL的结果是这个样子,4个数字表示成功金额、成功笔数、失败金额、失败笔数
123.45 11 2345.67 222
也可以用这样的简单SQL语句统计:
SELECT `支付状态`, COUNT(*), SUM(`支付金额`) FROM `订单`
结果为两行,分别是成功的笔数和金额、失败的比如和金额,例如是这样:
1 11 123.45
2 22 2345.67
SELECTo1.order_id,
MAX(o1.subtotal) AS 订单总金额,
SUM(o2.cost) AS 订单明细合计
FROM
`order` o1 JOIN order_details o2 ON (o1.order_id = o2.order_id)
GROUP BY
o1.order_id
HAVING
MAX(o1.subtotal) <>SUM(o2.cost)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)