一道比较实用的MySQL面试题:游戏数据充值查询
时间:2021-07-01 10:21:17
帮助过:35人阅读
SELECT MAX( amount ) , t.qqnumber, t.MONTH
FROM (
SELECT MONTH( a.paytime ) MONTH , b.qqnumber, SUM( a.amount ) amount
FROM payment a, members b
WHERE a.userid = b.userid AND YEAR( a.paytime ) = ‘2012‘ GROUP BY b.qqnumber, MONTH
) AS t GROUP BY t.MONTH;
方法二:
SELECT MAX( amount ) , t.qqnumber, t.month
FROM (
SELECT MONTH( p.paytime ) AS MONTH , SUM( p.amount ) AS amount, m.qqnumber AS qqnumber
FROM Members m
JOIN Payment p ON m.userid = p.userid
WHERE YEAR( p.paytime ) =2012 GROUP BY m.qqnumber, MONTH
) AS t
GROUP BY t.month;
最后查询到的结果如下:
本文为作者原创,转载请注明出处,不对之处欢迎指正,请留言!
一道比较实用的MySQL面试题:游戏数据充值查询
标签:span opera 用户表 sel 数据 color family 汇总 payment