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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:34:04+00:00 2026-05-27T08:34:04+00:00

We calculate bonuses based on estimated work completed divided by hours paid. There is

  • 0

We calculate bonuses based on estimated work completed divided by hours paid. There is a person in our system who isn’t paid by us and I want to remove him from the report.

In this query I am getting all of the tracked time on each batch for that user divided by the total time tracked on that batch, minus [name].

Batches have tasks which contain the estimated_nonrecurring and the estimated_recurring.
Batches have batch_logs which have the time_elapsed which is the time that the batch has been actually worked on.

What is happening is instead of selecting all the batches and then getting all the time that was tracked for that user in comparison to the total time tracked that wasn’t tracked by [name], it is ignoring every batch that has [name] as an entry in it.

Here is my select statement for ratios.

SELECT user_time_by_batch.batch_id, userid, user_time_by_batch / total_time_by_batch as ratio FROM 
( 
SELECT SUM(time_elapsed) user_time_by_batch, userid, batch_id 
FROM batch_log 
inner join batches on batch_log.batch_id = batches.id 
Where start_time between (?) and (?) 
   and end_time is not null and time_elapsed BETWEEN \"00:00:00\" AND \"10:00:00\" 
   and batch_id not in (\"-1\", \"-2\", \"-3\", \"-4\", \"-5\", \"-6\", \"-7\", \"-8\", \"-9\", \"-10\", \"-11\", \"-12\", \"-13\", \"-14\", \"-15\", \"-16\", \"-17\") 
   and batches.operation_id = ? 
   and batch_log.userid = ? 
GROUP BY batch_id, userid 
)  user_time_by_batch 
INNER JOIN 
( 
SELECT SUM(time_elapsed) total_time_by_batch, batch_id 
FROM batch_log 
inner join batches on batch_log.batch_id = batches.id 
Where start_time between (?) and (?)  
  and end_time is not null and time_elapsed BETWEEN \"00:00:00\" AND \"10:00:00\" 
  and batch_id not in (\"-1\", \"-2\", \"-3\", \"-4\", \"-5\", \"-6\", \"-7\", \"-8\", \"-9\", \"-10\", \"-11\", \"-12\", \"-13\", \"-14\", \"-15\", \"-16\", \"-17\") 
  and batches.operation_id = ? 
  and batch_log.userid != 'name' 
GROUP BY batch_id 
) total_time_by_batch 
ON user_time_by_batch.batch_id = total_time_by_batch.batch_id ;
  • 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-27T08:34:05+00:00Added an answer on May 27, 2026 at 8:34 am

    One thing I would consider trying is moving the batch_log.userid != ‘smacpherson’ in to the JOIN statement instead of in the WHERE clause. I’m not sure how best-practicey this is, but I’ve had success eliminating weird data issues by juggling that way.

    So:

    INNER JOIN 
    ( 
    SELECT SUM(time_elapsed) total_time_by_batch, batch_id 
    FROM batch_log 
    inner join batches on batch_log.batch_id = batches.id and batch_log.userid != 'smacpherson'
    Where start_time between (?) and (?)  
      and end_time is not null and time_elapsed BETWEEN \"00:00:00\" AND \"10:00:00\" 
      and batch_id not in (\"-1\", \"-2\", \"-3\", \"-4\", \"-5\", \"-6\", \"-7\", \"-8\", \"-9\", \"-10\", \"-11\", \"-12\", \"-13\", \"-14\", \"-15\", \"-16\", \"-17\") 
      and batches.operation_id = ?  
    GROUP BY batch_id 
    ) total_time_by_batch 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to calculate how much bandwidth a some Javascript code will consume, based
To calculate a top position for an element of variable height, I was thinking
How can I calculate the value of PI using C#? I was thinking it
How do I calculate the distance between two points specified by latitude and longitude?
How do I calculate the CRC32 (Cyclic Redundancy Checksum) of a string in .NET?
How do you calculate the distance between 2 cities?
I need to calculate Math.exp() from java very frequently, is it possible to get
How do you calculate the least common multiple of multiple numbers? So far I've
I need to calculate averages, standard deviations, medians etc for a bunch of numerical
How do I calculate the position of an accelerating body (e.g. a car) after

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.