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

  • Home
  • SEARCH
  • 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 7981171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:17:30+00:00 2026-06-04T10:17:30+00:00

Edit: I think I figured out the solution, but I’m still interested to know

  • 0

Edit: I think I figured out the solution, but I’m still interested to know if anyone has a better way to do it. Adding “GROUP BY name” produced the correct output.

I have a table like this:

Name    StartDate             EndDate
name0   2012-05-18 20:00:00   2012-05-18 20:00:01
name1   2012-05-18 20:00:00   2012-05-18 20:00:05
name0   2012-05-18 20:00:00   2012-05-18 20:00:01
name3   2012-05-18 20:00:00   2012-05-18 20:00:03
name4   2012-05-18 20:00:00   2012-05-18 20:00:07
name3   2012-05-18 20:00:00   2012-05-18 20:00:03
name8   2012-05-18 20:00:00   2012-05-18 20:00:12
name5   2012-05-18 20:00:00   2012-05-18 20:00:11
name1   2012-05-18 20:00:00   2012-05-18 20:00:05

I’m trying to learn how to do two things:

1) List distinct names with the COUNT of their rows and the SUM of their total run time

Name    Count   TotalRunTime
name0   2       2
name1   2       10
name3   2       6
name4   1       7
name5   1       11
name8   1       12

I created the following query to try to do both of these things at once. It works for a single name, but I can’t figure out how to make it ‘iterate’ over the list of distinct names in the table.

SELECT
  Name,
  SUM(TIME_TO_SEC(TIMEDIFF(enddate,startdate))) TotalRunTime,
  COUNT(*) as TotalJobs
FROM results
WHERE name='name0';

Which produces:

+-------+-------------+-----------+
| Name  |TotalRunTime | TotalJobs |
+-------+-------------+-----------+
| name0 |     1023491 |        46 |
+-------+-------------+-----------+
1 row in set (0.00 sec)

But what I want is:

+-------+-------------+-----------+
| Name  |TotalRunTime | TotalJobs |
+-------+-------------+-----------+
| name0 |     1023491 |        46 |
| name1 |      971621 |        35 |
| name3 |      108843 |        22 |
| ...   |         ... |       ... |
+-------+-------------+-----------+
<N> rows in set (0.00 sec)
  • 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-04T10:17:32+00:00Added an answer on June 4, 2026 at 10:17 am

    Group BY the name field is the best solution :

    SELECT
      Name,
      SUM(TIME_TO_SEC(TIMEDIFF(enddate,startdate))) TotalRunTime,
      COUNT(*) as TotalJobs
    FROM results
    WHERE name='name0'
    GROUP BY Name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I think I've figured out how to do the binary data part. Double
This is probably easily figured out, but I can't find a solution anywhere, for
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
This has happened many times before, but I never bothered to figure out why,
Edit I think there is some confusion, I am not using both of the
EDIT: This question was initially too general, I think. So What I really need
EDIT: I have fixed all but two warnings now, so thank you all for
I'm writing a virtual machine in C just for fun. Lame, I know, but
I have been trying to figure out a way to convert bitmap files into
I have been looking around online to try to find a complete solution but

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.