Last active
August 29, 2015 13:57
-
-
Save martypitt/9496603 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
## How many messages has Todd receied, by day? | |
select DATE(cm.`receivedDate`), count(*) from Inbox inbox | |
inner join InboxMessage im on inbox.id = im.`inbox_id` | |
inner join ChannelMessage cm on im.`message_id` = cm.id | |
where inbox.`user_id` = 2 | |
group by DATE(cm.`receivedDate`) | |
order by DATE(cm.`receivedDate`) desc; | |
## What channels did Todds messages come from on March 6th? | |
select channel_id, count(*) | |
from Inbox inbox | |
inner join InboxMessage im on inbox.id = im.`inbox_id` | |
inner join ChannelMessage cm on im.`message_id` = cm.id | |
where inbox.`user_id` = 2 | |
and DATE(cm.`receivedDate`) = '2014-03-06' | |
group by channel_id | |
order by count(*) desc; | |
## Which channels have lots of messages? | |
select channel_id, count(*) | |
from ChannelMessage | |
group by channel_id | |
order by count(*) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment