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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:28:51+00:00 2026-06-13T20:28:51+00:00

I realize this might not be an efficient select, but it works for now…mostly.

  • 0

I realize this might not be an efficient select, but it works for now…mostly. The problem I’m having is that if values aren’t submitted for both “iminutes” and “dminutes”… I get no data. I think if they both returned a value of “0” it would resolve this problem, but not sure how to get them to do that. Suggestions?

SELECT user,total.tuser_id, total.tminutes, 
    total.tminutes-indirect.iminutes AS itminutes, total.tminutes-direct.dminutes AS dtminutes

FROM

(SELECT U.user_name AS user,U.user_id AS tuser_id, SUM(M.minutes) AS tminutes
    From summary S
    JOIN users U ON U.user_id = S.user_id
    JOIN tasks TA ON TA.task_id = S.task_id
    JOIN tcompleted TC ON TC.tcompleted_id = S.tcompleted_id
    JOIN minutes M ON M.minutes_id = S.minutes_id
    JOIN hour_interval H ON H.hourinterval_id = S.hourinterval_id
    WHERE DATE(submit_date) = curdate()
    AND TIME(submit_date) BETWEEN '00:00:01' and '23:59:59'
    GROUP BY U.user_id) total
JOIN
    (SELECT U.user_id AS iuser_id, SUM(M.minutes) AS iminutes
    FROM summary S
    JOIN users U 
    ON U.user_id = S.user_id
    JOIN minutes M 
    ON M.minutes_id = S.minutes_id
    JOIN tasks TA 
    ON TA.task_id = S.task_id
    WHERE TA.task_type='indirect'
    AND DATE(submit_date) = curdate()
    AND TIME(submit_date) BETWEEN '00:00:01' and '23:59:59'
    GROUP BY U.user_id) AS indirect

ON  total.tuser_id = indirect.iuser_id
JOIN  
    (SELECT U.user_id AS duser_id, SUM(M.minutes) AS dminutes
    FROM summary S
    JOIN users U 
    ON U.user_id = S.user_id
    JOIN minutes M 
    ON M.minutes_id = S.minutes_id
    JOIN tasks TA 
    ON TA.task_id = S.task_id
    WHERE TA.task_type='direct'
    AND DATE(submit_date) = curdate()
    AND TIME(submit_date) BETWEEN '00:00:01' and '23:59:59'
    GROUP BY U.user_id) AS direct

ON  total.tuser_id = direct.duser_id

ORDER BY total.tuser_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-06-13T20:28:53+00:00Added an answer on June 13, 2026 at 8:28 pm

    COALESCE will return the first non-null value provided.

    total.tminutes-COALESCE(indirect.iminutes, 0)
    

    COALESCE here will return 0 when iminutes is NULL. You can do the same for dminutes.

    You may check the MySQL Reference Manual http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce

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

Sidebar

Related Questions

I realize this might not be a clear cut problem/answer question, but I think
I realize that this question might not make sense to some, but I was
I realize this might not be the best setup, but humor me, is it
I realize this question might not be that programming related, and that it by
I realize that this might be a duplicate question but this question is very
So, I realize this might not be the right site, but I didn't think
I realize that this is a question that will probably not have a single
I realize this might not be a best fit for SO, so please tell
Greets. I realize this might be seen as a duplicate question as this but
First of all, I realize this is a messy situation, but it's not of

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.