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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:12:32+00:00 2026-06-05T19:12:32+00:00

I am trying to create a report that pulls data from 2 tables: a

  • 0

I am trying to create a report that pulls data from 2 tables: a & b. The report is grouped by a.clock. Most of the data for the report comes from a – that part is working fine. a.clock links with b.userID.

The part i am struggling with is for one of the columns the data comes from b. I need to total up the following for each a.clock grouping in the main report (this query works standalone)

 SELECT (
   SUM(
     TIME_TO_SEC(
       TIMEDIFF(
         CONCAT(b.endDate, ' ', b.outTime),
         CONCAT(b.startDate, ' ', b.inTime)
       )
     ) / 3600
   )
 ) AS 'Misc Hours' FROM b

In other words, i need to total the Misc Hours (in b) for each a.clock. I thought maybe joining the b table was necessary but that didn’t seem to work. Any suggestions?

Here are the table definitions (sorry, verbose)

CREATE TABLE `a` (
  `laborID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0=sched; 1=accepted; 2=complete; 3=authorize',
  `laborType` varchar(15) NOT NULL DEFAULT '0' COMMENT 'Lookup',
  `hours` varchar(15) NOT NULL DEFAULT '',
  `wage` varchar(15) NOT NULL DEFAULT '',
  `id` int(10) unsigned NOT NULL DEFAULT '0',
  `laborDate` date NOT NULL,
  `ot` varchar(15) NOT NULL,
  `clock` varchar(15) NOT NULL,
  `setup` varchar(15) NOT NULL DEFAULT '',
  `ot2` varchar(15) NOT NULL,
  `wageOT1` varchar(15) NOT NULL,
  `wageOT2` varchar(15) NOT NULL,
  `inTime` varchar(15) NOT NULL,
  `outTime` varchar(15) NOT NULL,
  `startDateString` varchar(125) NOT NULL,
  `endDateString` varchar(125) NOT NULL,
  `authRequestDate` datetime NOT NULL,
  `authRequestUser` int(10) unsigned NOT NULL,
  `authRequestReason` text NOT NULL,
  `authDate` datetime NOT NULL,
  `authUser` int(10) unsigned NOT NULL,
  `authRequired` varchar(45) NOT NULL,
  `km` varchar(45) NOT NULL,
  `travelTime` varchar(45) NOT NULL,
  `actualInTime` varchar(45) NOT NULL,
  `actualOutTime` varchar(45) NOT NULL,
  `actualKm` varchar(45) NOT NULL,
  `actualTravelTime` varchar(45) NOT NULL,
  `intNotes` text,
  `extNotes` text,
  `billableReason` text,
  `billableHours` varchar(45) DEFAULT NULL,
  `actualHours` varchar(45) DEFAULT NULL,
  `overtime` varchar(45) DEFAULT NULL,
  `followUpReason` text NOT NULL,
  `responseType` varchar(45) DEFAULT NULL,
  `followUpType` int(10) unsigned DEFAULT NULL,
  `billableDrop` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`laborID`),
  KEY `id` (`id`),
  KEY `type` (`type`),
  KEY `laborDate` (`laborDate`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;


CREATE TABLE `b` (
  `timecodeID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `userID` int(10) unsigned NOT NULL,
  `inTime` varchar(45) NOT NULL,
  `outTime` varchar(45) NOT NULL,
  `startDateString` varchar(145) NOT NULL,
  `endDateString` varchar(145) NOT NULL,
  `startDate` varchar(45) NOT NULL,
  `endDate` varchar(45) NOT NULL,
  `type` varchar(45) NOT NULL,
  `comments` text NOT NULL,
  `multiDay` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY (`timecodeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • 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-05T19:12:34+00:00Added an answer on June 5, 2026 at 7:12 pm

    Well if you have multiple rows in each of the table then you will get larger sum as each row in labor will join with each row in timecodes. So the idea is to have nested query group by clock and userid to get one row each as per the groupping

    SELECT A.Clock, A.hours, B.'Misc Hours'
      FROM
         (
            SELECT labor.clock,
                   SUM(hours) Hours
              FROM labor
             GROUP BY labor.clock
         ) A
     INNER JOIN 
         (
            SELECT  timecodes.userID,
                    (SUM(
                         TIME_TO_SEC(
                              TIMEDIFF(
                                   CONCAT(timecodes.endDate,' ',timecodes.outTime),
                                   CONCAT(timecodes.startDate,' ',timecodes.inTime)
                              )
                          )/3600
                      )
                     ) AS 'Misc Hours'
             FROM timecodes
            GROUP BY timecodes.userID
    
    ) AS B ON A.Clock = B.UserId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Crystal Report that reads data from an access table.
i am trying to create a report from a row of data with about
I am trying to create a report that has a summary for each group.
I'm trying to create a report that needs to get the dates for last
I'm trying to create a report that displays for each months of the year
I am trying to create a report that will be delivered via email. Outlook
I'm trying to create a report from a proprietary ERP database. I've set up
I'm trying to create a report in Oracle ApEx that displays a list of
I am trying to create a report in SSRS2000 that will query an ORACLE
I'm trying to create a report that allows the user to select not only

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.