Created
June 10, 2011 02:37
-
-
Save bkilshaw/1018149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> describe urls; | |
+---------+--------------+------+-----+---------+----------------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+---------+--------------+------+-----+---------+----------------+ | |
| id | int(11) | NO | PRI | NULL | auto_increment | | |
| url | text | NO | | NULL | | | |
| userKey | varchar(255) | YES | | NULL | | | |
| userIp | varchar(255) | YES | | NULL | | | |
+---------+--------------+------+-----+---------+----------------+ | |
4 rows in set (0.00 sec) | |
mysql> describe clicks; | |
+------------+--------------+------+-----+---------+----------------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+------------+--------------+------+-----+---------+----------------+ | |
| id | int(11) | NO | PRI | NULL | auto_increment | | |
| url_id | int(11) | NO | MUL | NULL | | | |
| click_date | datetime | YES | | NULL | | | |
| ip | varchar(255) | YES | | NULL | | | |
+------------+--------------+------+-----+---------+----------------+ | |
4 rows in set (0.00 sec) | |
Statement: | |
SELECT urls.id, urls.url, count(clicks.id) as click_count FROM urls LEFT JOIN clicks ON urls.id = clicks.url_id WHERE urls.userKey = '$userKeyEscaped' GROUP BY clicks.url_id ORDER BY urls.id DESC LIMIT 25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment