显示对某一列的数据进行计数并汇总总金额的记录 [英] Show records that counts data of a certain column and summing up total amounts
本文介绍了显示对某一列的数据进行计数并汇总总金额的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示来自 mysql 数据库的记录,该记录对某一列的数据进行计数并汇总数量
I would like to show records from mysql database that counts data of a certain column and summing up the amounts
我有一个 sql 查询,其中我们将关注 MatchID 135
I have an sql query in which we will focus on MatchID 135
SELECT `BetType`,
`BetAmount`,
`Payout`
FROM `betdb`
LEFT JOIN `matchdb` ON `betdb`.`MatchID` = `matchdb`.`MatchID`
WHERE `betdb`.`MatchID`=135
它返回数据如
我想列出 BetTypes 及其计数、BetAmt Total 和 Payout Total 返回行,例如
I would like to list BetTypes and its Count, BetAmt Total and Payout Total return rows something like
BetType Count BetAmount Total Payout Total
Handi 2 60000 950000
Homerun Count 4 10000 0
Total 6 70000 950000
我尝试对 BetType 使用 DISTINCT,但它只返回第一行
I tried using DISTINCT for BetType but it just returns the first row
推荐答案
试试这个
SELECT `BetType`,
count(`BetType`) AS COUNT,
sum(`BetAmount`) AS BetAmountTotal,
sum(`Payout`) AS PayoutTotal
FROM `betdb`
LEFT JOIN `matchdb` ON `betdb`.`MatchID` = `matchdb`.`MatchID`
WHERE `betdb`.`MatchID`=135
GROUP BY `BetType`
这篇关于显示对某一列的数据进行计数并汇总总金额的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文