records within a quarter [message #345259] |
Tue, 02 September 2008 14:25  |
aarti81
Messages: 235 Registered: December 2007 Location: USA
|
Senior Member |
|
|
Hi all
I have the following query which gives me null and non-null records, but is there anway where i can get the null and non-null records for each quarter?
SELECT calc_type,
CASE WHEN DAYS IS NULL AND NON_NULL_RECORDS > (TOTAL_RECORDS)/2 THEN MAX(DAYS) OVER (PARTITION BY TO_CHAR(SELECTION_DATE,'yy"Q"q')ORDER BY NULL) ELSE DAYS END DAYS,
contract_number,
NTPACT,
SELECTION_DATE,
AMENDREQ,
RECPROP,
AMEND_STATUS_CODE,
AMENDMENT_NUMBER,
SELECTION_DATE AS PARAM_DATE,
TO_CHAR(SELECTION_DATE,'yy"Q"q') quarter,
T2.NULL_RECORDS,
T2.NON_NULL_RECORDS,
T2.TOTAL_RECORDS
FROM (SELECT DISTINCT ' Project Specific/Other' calc_Type
,TRUNC (NTPACT - Selection_Date) Days
,Contract_Number
,NTPACT
,SELECTION_DATE
,AMENDREQ
,RECPROP
,AMEND_STATUS_CODE
,AMENDMENT_NUMBER
,SELECTION_DATE AS PARAM_DATE
FROM contract_vw2
WHERE ( Contract_Type = 'Project Specific' OR contract_type = 'Other')
AND AMENDMENT_NUMBER=0
AND AMEND_STATUS_CODE NOT IN (4,33,34,35,36,37))T1,
(SELECT
COUNT(*) AS TOTAL_RECORDS,
SUM(CASE WHEN NTPACT IS NULL THEN 1 END) AS NULL_RECORDS,
SUM(CASE WHEN NTPACT IS NOT NULL THEN 1 END) AS NON_NULL_RECORDS
FROM contract_vw2
WHERE ( Contract_Type = 'Project Specific' OR contract_type = 'Other')
AND AMENDMENT_NUMBER=0
AND AMEND_STATUS_CODE NOT IN (4,33,34,35,36,37)
) T2
Thank You
|
|
|
|
|
|
|
|
|
|
Re: records within a quarter [message #345331 is a reply to message #345283] |
Wed, 03 September 2008 02:09   |
rajatratewal
Messages: 507 Registered: March 2008 Location: INDIA
|
Senior Member |
|
|
You are asked to post test case.
1)Create Table
1)Insert Statements
Here is a sample how to do that.
create table test
(
id number,
name varchar2(20)
);
insert into test values(1,'Test1');
insert into test values(2,'Test2');
If you need quick answers then always post a testcase.
Regards,
Rajat
|
|
|
Re: records within a quarter [message #345387 is a reply to message #345283] |
Wed, 03 September 2008 05:22   |
joicejohn
Messages: 327 Registered: March 2008 Location: India
|
Senior Member |
|
|
@aarti81,
Are you sure that was the result of your query? I am finding columns like contract_number, AMEND_STATUS_CODE, AMENDMENT_NUMBER which you have used in the query missing in the attached text file.
Quote: |
SELECT calc_type,
CASE WHEN DAYS IS NULL AND NON_NULL_RECORDS > (TOTAL_RECORDS)/2 THEN MAX(DAYS) OVER (PARTITION BY TO_CHAR(SELECTION_DATE,'yy"Q"q')ORDER BY NULL) ELSE DAYS END DAYS,
contract_number,
NTPACT,
SELECTION_DATE,
AMENDREQ,
RECPROP,
AMEND_STATUS_CODE,
AMENDMENT_NUMBER,
|
Cant help until you post test case and the proper output of the query you have posted... Also to be frank, I am a bit confused about what exactly are the problems you face with your query.
Regards,
Jo
|
|
|
Re: records within a quarter [message #345408 is a reply to message #345387] |
Wed, 03 September 2008 07:48  |
aarti81
Messages: 235 Registered: December 2007 Location: USA
|
Senior Member |
|
|
Some of the fileds that are not seen because they are just redundant, as i'm just trying to get the null and non-null records for each quarter.
Thanks
|
|
|