473,320 Members | 1,979 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,320 software developers and data experts.

Combine queries for single output

I want my output in two columns like this:

C_INCIDENT_TYPE \ TOTAL COUNT


How do I combine my two queries to get result.

First Query

SELECT C_INCIDENT_TYPE, COUNT (*)
FROM TABLE_AUDIT
WHERE SUBSTR(I_USER,7,2) IN ('AD','WF','F5')
AND SUBSTR(I_IMAGE_COPY,12,8) > '00000000'
AND SUBSTR(I_IMAGE_COPY,12,8) < '99999999'
AND D_H_STAMP BETWEEN '2007-06-01-00.37.30.124670' AND
'2007-06-30-00.37.30.124670'
GROUP BY C_INCIDENT_TYPE
ORDER BY 2
WITH UR


Second Query

SELECT C_INCIDENT_TYPE, COUNT (*)
FROM TABLE_AUDIT
WHERE SUBSTR(I_USER,7,2) NOT IN 'AD','WF','F5')
AND SUBSTR(I_IMAGE_COPY,12,8) > '00000000'
AND SUBSTR(I_IMAGE_COPY,12,8) < '99999999'
AND D_H_STAMP BETWEEN '2007-06-01-00.37.30.124670' AND
'2007-06-30-00.37.30.124670'
GROUP BY C_INCIDENT_TYPE
ORDER BY 2
WITH UR

The only statement difference between the two queries is: WHERE SUBSTR(I_USER,7,2) NOT IN 'AD','WF','F5') (The other query says 'IN')

That is my question... Thank You!
Aug 21 '07 #1
4 4192
r035198x
13,262 8TB
I want my output in two columns like this:

C_INCIDENT_TYPE \ TOTAL COUNT


How do I combine my two queries to get result.

First Query

SELECT C_INCIDENT_TYPE, COUNT (*)
FROM TABLE_AUDIT
WHERE SUBSTR(I_USER,7,2) IN ('AD','WF','F5')
AND SUBSTR(I_IMAGE_COPY,12,8) > '00000000'
AND SUBSTR(I_IMAGE_COPY,12,8) < '99999999'
AND D_H_STAMP BETWEEN '2007-06-01-00.37.30.124670' AND
'2007-06-30-00.37.30.124670'
GROUP BY C_INCIDENT_TYPE
ORDER BY 2
WITH UR


Second Query

SELECT C_INCIDENT_TYPE, COUNT (*)
FROM TABLE_AUDIT
WHERE SUBSTR(I_USER,7,2) NOT IN 'AD','WF','F5')
AND SUBSTR(I_IMAGE_COPY,12,8) > '00000000'
AND SUBSTR(I_IMAGE_COPY,12,8) < '99999999'
AND D_H_STAMP BETWEEN '2007-06-01-00.37.30.124670' AND
'2007-06-30-00.37.30.124670'
GROUP BY C_INCIDENT_TYPE
ORDER BY 2
WITH UR

The only statement difference between the two queries is: WHERE SUBSTR(I_USER,7,2) NOT IN 'AD','WF','F5') (The other query says 'IN')

That is my question... Thank You!
How do you want to combine the queries? The two conditions contradict so you can't get data that satisfies both conitions.
Aug 22 '07 #2
How do you want to combine the queries? The two conditions contradict so you can't get data that satisfies both conitions.
I understand that the two conditions contradict each other. My goal is to get the output so it looks like this.

Therefore output will have three columns

C_INCIDENT_TYPE | COUNT (From first Query | COUNT (from Second Query |
| | |

Would I use a join to run the query? Just asking?

Thank You!
Aug 22 '07 #3
r035198x
13,262 8TB
I understand that the two conditions contradict each other. My goal is to get the output so it looks like this.

Therefore output will have three columns

C_INCIDENT_TYPE | COUNT (From first Query | COUNT (from Second Query |
| | |

Would I use a join to run the query? Just asking?

Thank You!
I get what you're talking about now. I don't think joining the queries is the proper way of doing it. I'd suggest doing a little bit of arithmetic with it. If you have n records and your first query returns a records, then shouldn't your second query return n - a records?
Aug 22 '07 #4
Thanks, I will look into that more...
Aug 22 '07 #5

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

Similar topics

1
by: Chris Lutka | last post by:
I've been racking my brains all day over this. And I'm not the best at SQL either. I need a query that will produce the following results:...
0
by: MostlyH2O | last post by:
Hi Folks, I have a complex query that references a sub-query. It works fine when I call a sub-query from the main query (using design vew), but when I try to embed the SQL text of the...
4
by: Jason Gyetko | last post by:
Is there any way to combine these two queries into one? I have tables Item_Master & Kit_Master which are the source tables. Query 2 is using both Item_Master (table) & qryKit1 (query) &...
1
by: MackTheKnife | last post by:
I have the following 3 SQL statements that need to be combined, if possible. The output of one feeds the input of the next. I need to view all of the defined output fields (the output needs to be...
14
by: Pythor | last post by:
Hi, I need to data from several input fields, and treat them as if they were all the same field. I'm not describing this well, so I'll give an example: I have a table like this: Name ...
4
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If...
2
by: MLH | last post by:
Consider having tblCorrespondence, then copying & pasting it to tblCorrespondence1 - such that they are identical. Then consider the following UNION SELECT statement... SELECT...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
2
by: bips2005 | last post by:
i have got two queries, $sql1 = "select cust_id from customer where comp_name = '$compname'"; $result = $DB->query($sql1); $result->fetchInto($row); $sql = "select expirydate from...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.