Query using grouping

In this query, I have a table that has a remote address column called remoteaddr.

The problem is, I want a query that will return these remote addresses in ascending numerical order and each remote address is listed only once and the number of them is listed too. The sample table may look like,

+-----------------+
| remoteaddr      |
+-----------------+
| 123.123.123.123 |
| 124.124.124.124 |
| 125.125.125.125 |
| 123.123.123.123 |
| 123.123.123.123 |
| 126.126.126.126 |
| 125.125.125.125 |
| 123.123.123.123 |
+-----------------+
mysql> select remoteaddr, count(remoteaddr) as num_remoteaddr from iptable group by remoteaddr order by remoteaddr asc;

The output of the above query would be the following, given the sample data above.

+-----------------+----------------+
| remoteaddr      | num_remoteaddr |
+-----------------+----------------+
| 123.123.123.123 |              4 |
| 124.124.124.124 |              1 |
| 125.125.125.125 |              2 |
| 126.126.126.126 |              1 |
+-----------------+----------------+

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.