Skip to content

Instantly share code, notes, and snippets.

@martypitt
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martypitt/9496603 to your computer and use it in GitHub Desktop.
Save martypitt/9496603 to your computer and use it in GitHub Desktop.
## 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