adv_sample_user_queries_plus
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| adv_sample_user_queries_plus [2014/08/04 11:14] – daniel | adv_sample_user_queries_plus [2021/05/15 12:21] (current) – daniel | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Advanced | + | ==== Advanced |
| === Messages sent, with senders or recipients from a specific domain, but not tagged with a specified tag: === | === Messages sent, with senders or recipients from a specific domain, but not tagged with a specified tag: === | ||
| Line 14: | Line 14: | ||
| </ | </ | ||
| + | === Latest outgoing message per distinct recipient (to which a message was ever addressed): === | ||
| + | <code sql> | ||
| + | select mail_id from (select distinct on (m1.addr_id) m.mail_id, | ||
| + | from mail_addresses m1 join mail m using(mail_id) | ||
| + | where m1.addr_type=2 and m.status& | ||
| + | order by m1.addr_id, | ||
| + | </ | ||
| + | === Old messages, not archived or trashed, that belong to a thread whose most recent message | ||
| + | <code sql> | ||
| + | SELECT mail_id FROM mail m | ||
| + | WHERE status& | ||
| + | AND msg_date< | ||
| + | AND thread_id is not null | ||
| + | AND not exists | ||
| + | | ||
| + | WHERE m2.thread_id=m.thread_id | ||
| + | AND m2.msg_date> | ||
| + | </ | ||
| ---- | ---- | ||
| + | |||
| + | === Messages from the thread with the most unprocessed messages === | ||
| + | <code sql> | ||
| + | select mail_id from mail where thread_id in | ||
| + | (select thread_id | ||
| + | from mail | ||
| + | where status& | ||
| + | and thread_id is not null | ||
| + | group by thread_id | ||
| + | order by count(*) desc | ||
| + | limit 1 | ||
| + | ) | ||
| + | </ | ||
| See the [[http:// | See the [[http:// | ||
adv_sample_user_queries_plus.1407150843.txt.gz · Last modified: 2014/08/04 11:14 by daniel
