2012-07-06 42 views
1
id | userid | total_points_spent 
1 | 1  | 10 
2 | 2  | 15 
3 | 2  | 50 
4 | 3  | 5 
5 | 1  | 15 

通过上述表中删除重复的,我首先要去除的userid重复保持行与最大total_points_spent,就像这样:从一列保持全行

id | userid | total_points_spent 
3 | 2  | 50 
4 | 3  | 5 
5 | 1  | 15 

然后会喜欢总结total_points_spent的值,这将是容易的部分,导致70

+2

什么是你的mysql查询? – Jocelyn 2012-07-06 00:53:17

+0

你是什么意思? – Tyilo 2012-07-06 01:00:06

+0

2个表中显示的数字似乎是mysql查询的结果。如果确实如此,你能告诉我们这个mysql查询的代码吗?否则,你有什么尝试? – Jocelyn 2012-07-06 01:01:54

回答

2

我不确定你的意思是“删除”是删除或选择。以下是分别查询仅选择最大totalpointspend记录。

SELECT tblA.* 
    FROM (SELECT userid, MAX(totalpointspend) AS maxtotal 
      FROM tblA 
      GROUP BY userid) AS dt 
INNER JOIN tblA 
    ON tblA.userid = dt.userid 
    AND tblA.totalpointspend = dt.maxtotal   
ORDER BY tblA.userid