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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:21:16+00:00 2026-06-03T17:21:16+00:00

I have two very similar SQL queries that return a count of minutes spent

  • 0

I have two very similar SQL queries that return a count of minutes spent on a different work area.

Is it possible to condense them into one query?

Parameters needed:

Show the current month (IE 1 for Jan, 4 for April)
Show the total minutes count from both queries into one single query.

Here are the queries I have at the moment:

SELECT SUM(r.Minutes_Spent) AS 'Custom Programming and Consulting'
FROM TK_Project p
INNER JOIN TK_Task t
ON p.Project_ID = t.Project_ID JOIN TK_Time_Record r
ON t.ID = r.Task_ID
WHERE p.Company = 162
AND p.Name ='Technical Support'
AND r.Work_Date BETWEEN  '04/01/2001'  AND  '04/30/2012'
AND r.Type NOT LIKE '%non%'
AND (r.Type = 'Programming-Billable' OR r.Type = 'Consulting-Billable')

SELECT SUM(r.Minutes_Spent) AS 'Tech. Support / Data Maint. / Training'
FROM TK_Project p
INNER JOIN TK_Task t
ON p.Project_ID = t.Project_ID JOIN TK_Time_Record r
ON t.ID = r.Task_ID
WHERE p.Company = 162
AND p.Name ='Technical Support'
AND r.Work_Date BETWEEN  '04/01/2001'  AND  '04/30/2012'
AND r.Type NOT LIKE '%non%'
AND (r.Type = 'Data Maintenance' OR r.Type = 'Tech Support-Billable' OR r.Type = 'Training')

Here is the data they provide:

Custom Programming and Consulting
90

Tech. Support / Data Maint. / Training
105

Is it possible to get the above queries pushed into one query and it return the following data:

Month      Custom Programming and Consulting      Tech. Support / Data Maint. / Training
  4                    90                                           105

The month would need to show the current month that is in this part of the query:

AND r.Work_Date BETWEEN  '04/01/2001'  AND  '04/30/2012'

I’m not sure the best way to achieve this. I need the month because the next part I will need to upgrade this to is to go back 12 months from todays date for a graphical bar chart report.

  • 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-03T17:21:18+00:00Added an answer on June 3, 2026 at 5:21 pm

    Yes . . . you simply need case statements in the SELECT clause to group the values the way you need them:

    SELECT 
      SUM(case 
            when r.Type in ('Programming-Billable', 'Consulting-Billable')
            then r.Minutes_Spent
            end) AS "Custom Programming and Consulting",
      SUM(case 
            when (r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training')
            then r.Minutes_Spent
            end) AS "Tech. Support / Data Maint. / Training"
    FROM TK_Project p 
    INNER JOIN TK_Task t
      ON p.Project_ID = t.Project_ID 
    JOIN TK_Time_Record r
      ON t.ID = r.Task_ID
    WHERE p.Company = 162 
      AND p.Name ='Technical Support' 
      AND r.Work_Date BETWEEN  '04/01/2001'  AND  '04/30/2012' 
      AND r.Type NOT LIKE '%non%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that have virtually identical content and very similar structure. They
If I have two models that are very different, is it defeating the purpose
I have two very similar pieces of ASP.NET code that send a file in
I have two very similar classes that do essentially the same thing. The only
I have two pieces of code which are very similar in that they register
I have two classes (this is C#) that are very similar except they each
I have two very similar programs each trying to run two threads OddThread and
I have two very simple, identical UITableViews in my app that are populated with
I'm not very good in SQL and HQL... I have two domains: class Hotel
I have two very similar specs for two very similar controller actions: VoteUp(int id)

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.