+--------+------+---------------------+ | userId | Cmd | Time | +--------+------+---------------------+ | 1 | A | 2013-06-21 13:15:08 | | 1 | B | 2013-07-31 15:58:53 | | 3 | A | 2013-07-31 16:01:42 | | 4 | A | 2013-05-01 11:05:08 | | 4 | B | 2013-07-31 16:06:32 | | 6 | B | 2013-07-31 17:16:08 | | 7 | A | 2013-04-06 17:20:36 | | 3 | B | 2013-04-15 06:26:14 | | 7 | B | 2013-07-31 14:53:49 | | 6 | A | 2013-07-31 09:56:27 | +--------+------+---------------------+
How to get userIDs where their last Cmd is B?
Expected result:
+--------+------+---------------------+ | userId | Cmd | Time | +--------+------+---------------------+ | 1 | B | 2013-07-31 15:58:53 | | 4 | B | 2013-07-31 16:06:32 | | 6 | B | 2013-07-31 17:16:08 | | 7 | B | 2013-07-31 14:53:49 | +--------+------+---------------------+