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 8420747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:56:32+00:00 2026-06-10T02:56:32+00:00

DETAILS I want to find the difference between start and stop times(duration) for each

  • 0

DETAILS

I want to find the difference between start and stop times(duration) for each test taken then rank users according to the highest score and lowest duration for each test. Ultimately I will use PDO to do this in mysql. So far though I’ve just been working on the sql. I think I’m pretty close now, but am unsure how to combine the information into one query.

WHAT I’VE GOT(untested).

I have the following table called testresults

--------------------------------------------------------------------
| index | id |         start         |          stop        | score| 
--------------------------------------------------------------------
|   1   | 23 |   2012-06-06 07:30:20 | 2012-06-06 07:30:34  | 100  |
--------------------------------------------------------------------

In my select statement I want to get the id and the score along with the calculated duration.

I can get duration for any test taken today with the below query.

SELECT TIMESTAMPDIFF(SECOND,stop,start) AS duration
FROM testresults WHERE `start` >= DATE(NOW())

Then I sort the results based on rank. Rank is determined according to score and duration. Top place goes to the highest score with the shortest duration.I believe I can do that with something like this:

ORDER BY score DESC, duration ASC

I only want maybe 100 entries so,

LIMIT 100

QUESTION

How can I combine the above information into 1 query?

  • 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-10T02:56:34+00:00Added an answer on June 10, 2026 at 2:56 am
    SELECT `id`, `score`,
        TIMESTAMPDIFF( SECOND, start, stop ) AS `duration`
    FROM `testresults`
    WHERE `start` >= DATE(NOW())
    ORDER BY `score` DESC, `duration` ASC
    LIMIT 100;
    

    This will work pretty good. You’ll also need to put id & score in SELECT statement.

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

Sidebar

Related Questions

Here is the problem details: 1) I want to create dynamic (ip based) download
I want all build details to be saved in a text file.How to get
I want to get the details of the last run cron job. If the
I want to display the Itinerary details from developer.ean.com API. By passing the customer's
I want to know that how the details of the viewers could be traced
I want to access my Aweber account details and my email list in a
i want to get all the details of youtube,so if the user tick the
I want something that will receive me the processes details, like I receive with
I want to know how to get mp3 file details like artist, title, album
I want to know in which format the contact details are stored in android

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.