I need to retrieve distinct records from a column in a mysql table and then retrieve data from each row that the distinct records show up in. Sorry if this isn't very clear. I can elaborate if necessary.
EDIT:
+------+------+-----+
| ip | hits | day |
+------+------+-----+
| ip1 | 23 | 52 |
+------+------+-----+
| ip2 | 28 | 50 |
+------+------+-----+
| ip1 | 46 | 54 |
+------+------+-----+
| ip4 | 15 | 55 |
+------+------+-----+
| ip2 | 12 | 52 |
+------+-开发者_JAVA百科-----+-----+
I need to select distinct ips, then for each ip add up all the hits for that ip.
SELECT SUM(`hits`) AS `total_hits`, `ip`
FROM `ips`
GROUP BY `ip`
It doesn't sound like you need two queries, you just need to select distinct rows for the first column and then use a where clause for the additional data.
精彩评论