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

Including records in a query result that have no values

1
Feel free to critise/comment. I've been slightly thrown in at the deep end!

I'm building a query to count the number of test results that are unapproved, Out of spec, null etc per manufacturing site by Date(current month, last 12 months or all others).

I have the query returning results correctly but the only problem is it won't return 0's for the manufacturng sites that have none of the above.

Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT  CDA.MANUFACTURING_SITES.MANUFACTURING_SITE_NAME, 
  2.     -- CDA.TESTS.TEST_DATE,
  3.     COUNT(CDA.RESULTS.RESULT_ID),
  4.     COUNT( CASE WHEN CDA.RESULTS.IS_APPROVED = 0 THEN 1 END) UNAPPROVED,
  5.     COUNT( CASE WHEN  CDA.RESULTS.ACTUAL_RESULT IS NULL THEN 1 END) NO_RESULT,
  6.     COUNT(CASE WHEN CDA.RESULTS.ACTUAL_RESULT IS NOT NULL AND CDA.RESULTS.ACTUAL_RESULT > CDA.RESULTS.RESULT_REFERENCE_LIMIT THEN 1 END) OUT_OF_SPEC--,
  7. FROM 
  8.     CDA.MANUFACTURING_SITES,
  9.     CDA.BATCHES,
  10.     CDA.TESTS,
  11.     CDA.RESULTS
  12. WHERE
  13.     CDA.MANUFACTURING_SITES.MANUFACTURING_SITE_ID = CDA.BATCHES.MANUFACTURING_SITE_ID (+)
  14.     AND CDA.BATCHES.BATCH_ID = CDA.TESTS.BATCH_ID (+)
  15.     AND CDA.TESTS.TEST_ID =  CDA.RESULTS.TEST_ID (+)
  16.     AND TO_CHAR(CDA.TESTS.TEST_DATE,'MM-YYYY') = TO_CHAR(SYSDATE, 'MM-YYYY') --CURRENT MONTH
  17. GROUP BY CDA.MANUFACTURING_SITES.MANUFACTURING_SITE_NAME--, CDA.TESTS.TEST_DATE
  18. ORDER BY CDA.MANUFACTURING_SITES.MANUFACTURING_SITE_NAME
  19.  
  20.  

output:

MANUFACTURING_SITE_NAME: Ireland
COUNT(CDA.RESULTS.RESULT_ID): 8
UNAPPROVED: 8
NO_RESULT: 7
OUT_OF_SPEC: 1

Is there a way I can get the the other mamufacturing sites returned with 0's as their results returned?

Any input would be greatly appreciated. It you have any questions give me a shout.

Thanks
Jul 12 '07 #1
1 1312
debasisdas
8,127 Expert 4TB
I think you are getting what you have asked for in the query using all those joins.
Jul 12 '07 #2

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

Similar topics

6
by: cjm | last post by:
I need to group records and assign a setid to the group. I have a table with data that looks like this ColA ColB 94015 01065 94016 01065 94015 01085 94015 01086 33383 00912 32601 00912
1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
20
by: Guru | last post by:
Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to...
3
by: Peter Phelps | last post by:
My problem is as follows: I need automatically iterate through a single field in a table and use the values in the field to create an in-statement. Currently, the character limitation in the...
1
by: RiesbeckP | last post by:
Hi All, I have a DB where there are customer numbers and a few other fields. I want to be able to pull all of the null records for a particular field as well as all the other customer numbers...
7
by: GJPeacock | last post by:
Hi all, Please excuse my limited technical knowledge of PHP, so far i have only created PHP sites using Dreamweaver, i find know that i need features outside of it's capabilities. I am trying...
5
by: redstamp | last post by:
Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field. To explain, I have a table of...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
1
by: Rantoun | last post by:
I know what I am asking for is pretty hard, but still maybe there is someone out there who is able to solve my problem! I have a table that look like this CREATE TABLE VEHICLETRIPS ( VID...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.