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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:25:20+00:00 2026-05-22T12:25:20+00:00

My question about My SQL is, I have a table where users enter time

  • 0

My question about My
SQL is,

I have a table where users enter time reporting data called time_report. Each time_report is entered with a service code, each of which has a different meaning and includes a start, stop, time and total.

Here is a example of data entered in the time_report table.

t_id Date User Customer Service Closing System  Part    Start   Stop    Total

53 2011-05-02 13 0   48 4   0   0   09:00   17.15   8.15

54 2011-05-03 13 0   49 4   0   0   09:00   17:00    8

55 2011-05-04 13 0   48 4   0   0   09:00   17.15   8:15

61 2011-05-04 1  0  52  4   0   0   09:00   17.15   8:15

62 2011-05-05 1  0  48  4   0   0   09:00   17.15   8:15

I am trying to run a query to extract 3 pieces of information.

user ( the user is the foreign key to users.user_id)
sum(total) per user.
sun(total) per user where service < 49 
Utilization Percentage: (This will be calculated by dividing the 2 totals )

Service is the foreign key to servicecodes.s_id

When I try and run the query to get the sum(total it work okay but I cannot group the information together

mysql> SELECT  Users.full_name,sum(total)

    -> FROM time_report, users
    -> WHERE time_report.User = users.user_id
    -> AND date
    -> BETWEEN '2011-0502'
    -> AND '2011-05-11'
    -> GROUP BY User;
+-----------------+------------+
| full_name       | sum(total) |
+-----------------+------------+
| Cian Higgins    |         26 |
| Wallace Ward    |         23 |
| jason ward      |         42 |
| Thomas Woods    |         72 |
| Peter Jones     |         49 |
| fintan corrigan |         40 |
| David Jones     |         35 |
| January Jones   |         23 |
| Joe Johnson     |         24 |
+-----------------+------------+
9 rows in set, 1 warning (0.09)

When I run the query with the service < 49

SELECT  Users.full_name,sum(total) AS Productive

FROM time_report, users
WHERE time_report.User = users.user_id
AND date
BETWEEN '2011-0502'
AND '2011-05-11'
AND Service < 49
GROUP BY User;
+-----------------+------------+
| full_name       | Productive |
+-----------------+------------+
| Cian Higgins    |         14 |
| Wallace Ward    |         23 |
| jason ward      |         33 |
| Thomas Woods    |         53 |
| Peter Jones     |         41 |
| fintan corrigan |         32 |
| David Jones     |         27 |
| January Jones   |         23 |
| Joe Johnson     |         24 |
+-----------------+------------+
9 rows in set, 1 warning (0.03 sec)

But If I try and join the reports, I get errors….also if I try and run it as a subquery i get errors

Example:

SELECT Users.full_name, sum( total ) 
FROM time_report, users
WHERE time_report.User = users.user_id
AND date
BETWEEN '2011-0502'
AND '2011-05-11'
GROUP BY User
UNION 
SELECT Users.full_name, sum( total ) AS Productive
FROM time_report, users
WHERE time_report.User = users.user_id
AND date
BETWEEN '2011-0502'
AND '2011-05-11'
AND Service <49
GROUP BY User 

this gives all the results in the one row

full_name sum(total) 
Cian Higgins 26 
Wallace Ward 23 
jason ward 42 
Thomas Woods 72
 Peter Jones 49
 fintan corrigan 40 
David Jones 35 
January Jones 23 
Joe Johnson 24 
Cian Higgins 14 
jason ward 33 
Thomas Woods 53
 Peter Jones 41 
fintan corrigan 32 
David Jones 27 
  • 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-05-22T12:25:21+00:00Added an answer on May 22, 2026 at 12:25 pm

    You could use a CASE statement to refine the sum and have both sums returned with one statement.

    SELECT  Users.full_name
            ,sum(total)
            ,sum(case when service < 49 then total else 0 end) AS Productive
    FROM    time_report
            , users
    WHERE   time_report.User = users.user_id
            AND date BETWEEN '2011-0502' AND '2011-05-11'
    GROUP BY 
            User
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some question about DataGridView . I can show table in DataGridView ,
So I have about 150 SQL Server 2005 databases all mostly copies of each
Hi Experts I have a special question About dynamic Linq to Sql. Consider we
Hi I have a question about SUM in sql, I have a query that
I know there have been questions in the past about SQL 2005 versus Lucene.NET
I've got a quick question about default values in PL/SQL functions in Oracle. Take
So I was thinking about creating a dynamic sql question, meaning that i want
I recently asked a question about what I called method calls. The answer referred
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex

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.