Mysql查询仅在条件满足group by时选择sum()

时间:2014-07-17 10:38:30

标签: php mysql

我正在开设一个包含投注竞赛的网站

我想要做的是在本月从名为match

的表中选择TOP 10球员

这是mysql表的照片

enter image description here

我需要mysql查询,SELECT SUM(moguci_dobitak)FROM匹配仅当rezultat ='win'且日期是当前月份和当前年份GROUPED BY用户

翻译

moguci_dobitak =利润

rezultat =结果

感谢。

3 个答案:

答案 0 :(得分:1)

尝试类似:

SELECT SUM(moguci_dobitak) 
FROM matches 
WHERE rezultat='win' AND MONTH(date) = MONTH(NOW())
GROUP BY user

答案 1 :(得分:0)

SELECT TOP 2 * FROM匹配其中rezultat ='win'和DATE_SUB(CURDATE(),INTERVAL 30 DAY)< = date_col group by User;

答案 2 :(得分:0)

SELECT SUM(moguci_dobitak) 
FROM matches 
WHERE rezultat='win' 
AND MONTH(date) = MONTH(NOW())
AND YEAR(date) = YEAR(NOW())
GROUP BY user