COUNT(DISTINCT trEmail ) as clicks
, trEmail FROM table
GROUP BY trEmail
ORDER BY clicks DESC
will probably give what you are looking for
From: Tim Thorburn [mailto:webmaster@stripped]
Sent: 15 June 2003 00:14
Subject: selecting DISTINCT and COUNT in MySQL
I'm setting up a small tracking program for a site I'm working on -
basically it monitors all external web and email links that are clicked
from our site and stores them into a MySQL database.
Now I'm trying to extract the information from the database and display it
on screen with PHP. I've made a query which reads:
SELECT DISTINCT trEmail FROM db-name;
This clearly selects all the distinct email addresses from my table, but I
would like to put a count beside each of the distinct addresses to show how
many times each link was clicked.
For example, I'd like it to look something like the following:
email address # sent
Meaning that the email addresses 'fake@stripped' was clicked a total of 12
I'm thinking there should be a way to do this with a single SQL query ...
although after most of the day of trying and searching google - I've come
up with nothing but a headache.
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=1