Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save StoneCypher/eadd71eece25a1f8c66d to your computer and use it in GitHub Desktop.

Select an option

Save StoneCypher/eadd71eece25a1f8c66d to your computer and use it in GitHub Desktop.
mysql> create table ulog(userid integer, ltype integer);
Query OK, 0 rows affected (0.05 sec)
mysql> insert into ulog values(1,1), (1,2), (2,1), (2,3), (3,1), (4,1), (4,1), (4,1), (4,2), (4,1), (1,2);
Query OK, 11 rows affected (0.01 sec)
Records: 11 Duplicates: 0 Warnings: 0
mysql> select userid, ltype, count(ltype) from ulog group by userid, ltype;
+--------+-------+--------------+
| userid | ltype | count(ltype) |
+--------+-------+--------------+
| 1 | 1 | 1 |
| 1 | 2 | 2 |
| 2 | 1 | 1 |
| 2 | 3 | 1 |
| 3 | 1 | 1 |
| 4 | 1 | 4 |
| 4 | 2 | 1 |
+--------+-------+--------------+
7 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment