Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8464707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:50:06+00:00 2026-06-10T14:50:06+00:00

I’ve been racking my brain about how to do this in one query without

  • 0

I’ve been racking my brain about how to do this in one query without PHP code.

In a nutshell, I have a table that records email activity. For the sake of this example, here is the data:

recipient_id     activity     date
1                delivered    2011-08-30
1                open         2011-08-31
2                delivered    2011-08-30
3                delivered    2011-08-24
3                open         2011-08-30
3                open         2011-08-31

The goal: I want to display to users a single number that tells how many recipients open their email within 24 hours.

E.G. “Users that open their email within 24 hours: 13 Readers”

In the case of the sample data, above, the value would be “1”. (Recipient one was delivered an email and opened it the next day. Recipient 2 never opened it and recipient 3 waited 5 days.)

Can anyone think of a way to express the goal in a single query?

Reminder: In order to count, the person must have a ‘delivered’ tag and at least one ‘open’ tag. Each ‘open’ tag only counts once per recipient.

** EDIT ** Sorry, I’m using MySQL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:50:07+00:00Added an answer on June 10, 2026 at 2:50 pm

    Here is a version in mysql.

    select count(distinct recipient_id)
    from email e1
    where e1.activity = 'delivered'
      and exists
            (select * from email e2
             where e1.recipient_id = e2.recipient_id
               and e2.activity = 'open'
               and datediff(e2.action_date,e1.action_date) <= 1)
    

    The basic principle is that you want to find a delivered row for a recipient that also has an open within 24 hours.

    The datediff() is a good way to do the date arithmetic in mysql — other dbs will vary on exact methods for this step. The rest of the sql will work anywhere.

    SQLFiddle here: http://sqlfiddle.com/#!2/c9116/4

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.