473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

joining queries together

i have two queries I want to join so i can get the percentages from each department of completed work orders but not sure how to go about it. I know i want a join and a crosstab query so i can display the results in a report.
The first query calculates the numerator,

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(MaximoReport.WorkOrder) AS CountOfWorkOrder, 
  2.        MaximoReport.[Assigned Owner Group] 
  3. FROM MaximoReport
  4. WHERE (((MaximoReport.WorkType) In ("PMINS","PMOR","PMPDM","PMREG","PMRT")) 
  5. AND ((MaximoReport.Status) Like "*COMP") 
  6. AND ((MaximoReport.[Target Start])>=DateAdd("h",-1,[Enter the start date]) 
  7. And (MaximoReport.[Target Start])<DateAdd("h",23,[Enter the end date])) 
  8. AND ((MaximoReport.ActualLaborHours)<>"00:00") 
  9. AND ((MaximoReport.ActualStartDate)>=DateAdd("h",-11.8,[Enter the start date]) 
  10. And (MaximoReport.ActualStartDate)<DateAdd("h",23,[Enter the end date])))
  11. GROUP BY MaximoReport.[Assigned Owner Group];
while the second query calculates the denominator:

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(MaximoReport.WorkOrder) AS CountOfWorkOrder, 
  2.        MaximoReport.[Assigned Owner Group]
  3. FROM MaximoReport
  4. WHERE (((MaximoReport.WorkType) In ("PMINS","PMOR","PMPDM","PMREG","PMRT")) 
  5. AND ((MaximoReport.Status)<>"CAN") 
  6. AND ((MaximoReport.[Target Start])>=DateAdd("h",-11.8,[Enter the start date]) 
  7. And (MaximoReport.[Target Start])<DateAdd("h",23,[Enter the end date])))
  8. GROUP BY MaximoReport.[Assigned Owner Group];
please advise how i cann join the two queries to get the percentages of the departments and then do a crosstab query.
If there a better way of doing this please also let me know.

Thought of running the query this way but I get errors.

Expand|Select|Wrap|Line Numbers
  1. SELECT SUM(iif((MaximoReport.Status Like "*COMP"),iif((MaximoReport.ActualLaborHours<>"00:00"),1,0),0)) AS CountCompleted,
  2.        SUM(iif((MaximoReport.Status) <> "CAN",1,0)) AS CountTotal, 
  3.        Round([CountCompleted]/[CountTotal]*100,1) AS PercentCompleted, 
  4.        MaximoReport.[Assigned Owner Group]
  5. FROM MaximoReport
  6. WHERE (((MaximoReport.WorkType) In ("PMINS","PMOR","PMPDM","PMREG","PMRT")) 
  7. AND ((MaximoReport.[Target Start])>=DateAdd("h",-1,[Enter the start date]) 
  8. AND (MaximoReport.[Target Start])<DateAdd("h",23,[Enter the end date])) 
  9. AND ((MaximoReport.ActualStartDate)>=DateAdd("h",-11.8,[Enter the start date]) 
  10. AND (MaximoReport.ActualStartDate)<DateAdd("h",23,[Enter the end date])))
  11. GROUP BY MaximoReport.[Assigned Owner Group];
Feb 1 '19 #1
8 1275
twinnyfo
3,653 Expert Mod 2GB
Similar to yours, but try this (I can't vouch for my parentheses):

Expand|Select|Wrap|Line Numbers
  1. SELECT MaximoReport.[Assigned Owner Group], 
  2.        Sum(IIf([MaximoReport].[Status] Like "*COMP", 1, 0)) AS CompleteWorkOrders,
  3.        Sum(IIf([MaximoReport].[Status]<>"CAN", 1, 0)) AS TotalWorkOrders, 
  4.        Round(CompleteWorkOrders/CompleteWorkOrders*100, 1) AS PercentCompleted 
  5. FROM MaximoReport
  6. WHERE (((MaximoReport.WorkType) In ("PMINS","PMOR","PMPDM","PMREG","PMRT")) 
  7. AND (((MaximoReport.[Target Start])>=DateAdd("h",-1,[Enter the start date]) 
  8. And (MaximoReport.[Target Start])<DateAdd("h",23,[Enter the end date])) 
  9. AND ((MaximoReport.ActualLaborHours)<>"00:00") 
  10. AND ((MaximoReport.ActualStartDate)>=DateAdd("h",-11.8,[Enter the start date]) 
  11. And (MaximoReport.ActualStartDate)<DateAdd("h",23,[Enter the end date])))
  12. GROUP BY MaximoReport.[Assigned Owner Group];
Feb 1 '19 #2
when i do that it doesnt get the right results for department presentages
Feb 1 '19 #3
The numbers are not coming out is there a better way to do what im trying if i run the department queries seperate they work but when i try to do it with one query the numbers dont match.
Feb 1 '19 #4
twinnyfo
3,653 Expert Mod 2GB
I trust that your response is correct. However, how do you know that the values are incorrect? What indicators do you have that the total work orders and the total complete work orders are not being counted correctly.

This is what troubleshooting is all about.

I.e., which records are being missed that should be included or which records are included that should be excluded? Then, after you look at those records, we determine how to include/exclude them....
Feb 1 '19 #5
Because i took the cheese department and calculated the cheese department which is 159/184 and i 86.41 but when i run the queries with all the drpartments i get 95.2
Feb 1 '19 #6
twinnyfo
3,653 Expert Mod 2GB
And what are those same values with the new query (not just the percentage)? Which records are missing and why. This is what you need to figure out.

Keep in mind that from this thread and previous threads concerning this group of queries. I am still confused by the ActualLaborHours<>“00:00”. I guess, either it is a work order or it’s not. BUT—I don’t really understand what it represents....
Feb 1 '19 #7
I need to count the work orders for each department that is comp ,fcomp with actual labor hours that the work order was complete not in 00:00 and between the the start date and end date.
Feb 1 '19 #8
twinnyfo
3,653 Expert Mod 2GB
However, you’re still not telling us which records are being included or excluded, based upon the query.

When asked a specific question, please provide an answer.

Based upon the queries you provided, it “appears” the the only differences between the queries is the actual start/stop dates and the ActualLaborHours.... It would seem logical that you would want to compare apples to apples and not apples to oranges.
Feb 1 '19 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Frank.Sebesta | last post by:
I would like to run two queries together with the results together in one report. I would also want to extract only the duplicate records or have only the duplicate record show up in the results....
4
by: kevcar40 | last post by:
Hi i have a table which records the number of cards issued to a team fields are Team text Numof yellow integer numor Red integer date yellow short...
5
by: cody | last post by:
Hi, I have multiple Collections which I want to iterate over *without* copying alle my collections into one. If there is no method to do this I propose a new Class Enumerate which should provide...
1
by: Benny Schudel | last post by:
Howto put these two queries together? sql = "SELECT DISTINCT medium_id, COUNT(tag) AS count FROM tags WHERE tag = 'test' GROUP BY medium_id ORDER BY count DESC" This query is working. Id...
5
by: Ian Davies | last post by:
Hello I am trying to update a session, ie everytime the page is resubmitted I want the current selected value from a list to be appended to the old session value. I have the following code but am...
5
by: listerofsmeg01 | last post by:
Hi, Pretty new to PHP and MySQL. I have a page on my site that displays a lot of information from various tables. Currently I have lots of small PHP wrapper functions around SQL queries to...
3
by: atiq | last post by:
I am tyring to join two join fields together in a Report in the follwoing format: Date: Time: i have attempted this using the following code, but doesnt work: ="Date:" & " " & & " " &...
1
by: nsymiakakis | last post by:
Hi everyone, I have two seperate queries that work great individually, but I need to join them together to get a combined output. Can someone look at these and help me with the code? Here are the 2...
6
by: Serenityquinn15 | last post by:
Hi! I have a problem in my query... I want to join my two tables with the same date and returns in different records but it returns duplicate record.. Here is the examples: Table1: Field1 ...
1
by: Vasago | last post by:
I have a couple different tables(time work and Scheduled time) that are coming together to give employees actual worked times and their scheduled times to work. The first queries uses (date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.