Invalid Identifier error message on left outer join using subqueries - sql

This query only works if i replace the top select columns with "*". I've been reading through the other questions that are similar to mine but i haven't been able to apply their logic to my situation. All of the subqueries are the same except that they change based on the state in the "where" clauses.
There are far more successes everyday. Failures and warnings don't happen happen everyday so they have some null values that I would like to make into 0's. I want all of the successes, warnings, and failures to be related to the a.Start_date.
Select a.START_DATE, a.Successes, b.START_DATE, b.Failures, c.START_DATE, c.WARNINGS
FROM
(
Select
(Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END) "START_DATE",
NVL(count(job_id),0) as "Successes"
from NI_INFA_ACTIVITY_LOG_V
where State = 1
and
(:P1_JOB_SIZE_CHOOSER = 'Tiny' AND (1440*(END_TIME - START_TIME)) <= 1
OR
:P1_JOB_SIZE_CHOOSER = 'Small' AND (1440*(END_TIME - START_TIME)) > 1 AND
(1440*(END_TIME - START_TIME)) <= 5
OR
:P1_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5 AND
(1440*(END_TIME - START_TIME)) <= 20
OR
:P1_JOB_SIZE_CHOOSER = 'Large' AND ((1440*(END_TIME - START_TIME)) > 20)
OR
:P1_JOB_SIZE_CHOOSER NOT IN('Small','Medium','Large','Tiny') AND (1440*(END_TIME - START_TIME)) > 0)
group by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
order by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
) a
left outer join
(
Select
(Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END) "START_DATE",
nvl(count(job_id),0) as "Failures"
from NI_INFA_ACTIVITY_LOG_V
where State = 3
and
(:P1_JOB_SIZE_CHOOSER = 'Tiny' AND (1440*(END_TIME - START_TIME)) <= 1
OR
:P1_JOB_SIZE_CHOOSER = 'Small' AND (1440*(END_TIME - START_TIME)) > 1 AND
(1440*(END_TIME - START_TIME)) <= 5
OR
:P1_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5 AND
(1440*(END_TIME - START_TIME)) <= 20
OR
:P1_JOB_SIZE_CHOOSER = 'Large' AND ((1440*(END_TIME - START_TIME)) > 20)
OR
:P1_JOB_SIZE_CHOOSER NOT IN('Small','Medium','Large','Tiny') AND (1440*(END_TIME - START_TIME)) > 0)
group by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
order by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
) b
on
a.START_DATE = b.START_DATE
left outer join
(
Select
(Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END) "START_DATE",
nvl(count(job_id),0) as "Warnings"
from NI_INFA_ACTIVITY_LOG_V
where State = 2
and
(:P1_JOB_SIZE_CHOOSER = 'Tiny' AND (1440*(END_TIME - START_TIME)) <= 1
OR
:P1_JOB_SIZE_CHOOSER = 'Small' AND (1440*(END_TIME - START_TIME)) > 1 AND
(1440*(END_TIME - START_TIME)) <= 5
OR
:P1_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5 AND
(1440*(END_TIME - START_TIME)) <= 20
OR
:P1_JOB_SIZE_CHOOSER = 'Large' AND ((1440*(END_TIME - START_TIME)) > 20)
OR
:P1_JOB_SIZE_CHOOSER NOT IN('Small','Medium','Large','Tiny') AND (1440*(END_TIME - START_TIME)) > 0)
group by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
order by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
) c
on
a.START_DATE = c.START_DATE
ORDER BY
a.START_DATE
At the end, I would like to have the results be something like:
Start_Date Successes Warnings Failures
6/1/2015 5 0 3
........ 8 15 4
6/30/2015 9 1 0

You've used quoted identifiers for (some of) the aliases in your subqueries, so you have to quote those in the outer select too, and exactly match the case you used:
Select a.START_DATE, a."Successes",
b.START_DATE, b."Failures",
c.START_DATE, c."Warnings"
...
Quoted identifiers are a pain. If you want the column titles to be mixed-case you could use unquoted identifiers in the subqueries and apply a final quoted name in ther outer query as another alias; or let the client handle that display issue.
And since start_date is the join condition, you probably don't want all three references; and to get the zeros in the result set you'll need to NVL the failure and warning counts, so you might as well use unquoted identifiers anyway:
Select a.start_date "Start date", a."Successes",
nvl(b.failures, 0) "Failures", nvl(c.warnings, 0) "Warnings"
...
NVL(count(job_id),0) as successes
...
The NVL you already have around the count isn't doing anything though - it needs to be in the outer query instead as shown - because there is no start date value to group by if the count is null.
If the subqueries really are so similar you could simplify this to a single query level with three selective counts; something like:
Select to_char(Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END, 'MM/DD/YYYY') as "Start date",
count(case when State = 1 then job_id end) as "Successes",
count(case when State = 3 then job_id end) as "Failures",
count(case when State = 2 then job_id end) as "Warnings"
from NI_INFA_ACTIVITY_LOG_V
where (:P1_JOB_SIZE_CHOOSER = 'Tiny'
AND (1440*(END_TIME - START_TIME)) <= 1)
OR (:P1_JOB_SIZE_CHOOSER = 'Small'
AND (1440*(END_TIME - START_TIME)) > 1
AND (1440*(END_TIME - START_TIME)) <= 5)
OR (:P1_JOB_SIZE_CHOOSER = 'Medium'
AND (1440*(END_TIME - START_TIME)) > 5
AND (1440*(END_TIME - START_TIME)) <= 20)
OR (:P1_JOB_SIZE_CHOOSER = 'Large'
AND (1440*(END_TIME - START_TIME)) > 20)
OR (:P1_JOB_SIZE_CHOOSER NOT IN ('Small','Medium','Large','Tiny')
AND (1440*(END_TIME - START_TIME)) > 0)
group by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END
order by Case :P1_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END;
Your parentheses seem to be out of whack too, so I've attempted to correct those, but you may have been doing something intentional I didn't follow...

Replace
Select a.START_DATE, a.Successes, b.START_DATE, b.Failures, c.START_DATE, ...
by
Select a."START_DATE", a."Successes", b."START_DATE", b."Failures", c."START_DATE", ...

Related

How to insert a dynamic where clause within a case when in ATHENA

i have this query
SELECT case
when {{aggtime}} = 'HOURLY' then parsedatetime(formatdatetime("PUBLIC"."ORDERS"."CREATED_AT", 'yyyyMMddHH'), 'yyyyMMddHH')
when {{aggtime}} = 'DAILY' then CAST("PUBLIC"."ORDERS"."CREATED_AT" AS date)
when {{aggtime}} = 'WEEKLY' then dateadd('day', CAST((1 - CASE WHEN ((iso_day_of_week("PUBLIC"."ORDERS"."CREATED_AT") + 1) % 7) = 0 THEN 7 ELSE ((iso_day_of_week("PUBLIC"."ORDERS"."CREATED_AT") + 1) % 7) END) AS long), CAST("PUBLIC"."ORDERS"."CREATED_AT" AS date))
when {{aggtime}} = 'MONTHLY' then parsedatetime(formatdatetime("PUBLIC"."ORDERS"."CREATED_AT", 'yyyyMM'), 'yyyyMM')
when {{aggtime}} = 'YEARLY' then parsedatetime(formatdatetime("PUBLIC"."ORDERS"."CREATED_AT", 'yyyy'), 'yyyy')
END
AS "CREATED_AT", sum("PUBLIC"."ORDERS"."QUANTITY") AS "sum"
FROM "PUBLIC"."ORDERS"
WHERE year(CREATED_AT)=2020 and month(CREATED_AT) = 1 and day(CREATED_AT) = 01
GROUP BY "CREATED_AT"
i need the where clause only when {{aggtime}}='HOURLY', otherwise i need only the year
How can i achieve it ?
ps :. {{aggtime}} is a parameter for Metabase

Adding query referencing another table in main and sub-selects

I have a table for showing target and completion times and all of the information is from one table "job" - however I now want to add some more SQL in to provide some information from another table "job_type" but whenever I keep getting error messages saying
"SQLSTATE = S0022 [Oracle][ODBC][Ora]ORA-00904: "JOB_TYPE"."JOB_TYPE_CODE": invalid identifier.
The code I have that works (without the bit I want adding is)
select
job_number, priority_code, job_entry_date, clock_start,
site_code,
TO_CHAR(job_entry_date, 'Dy') as DAY_LOGGED,
TO_CHAR(actual_start_date, 'IW') as WEEK_ON_SITE,
actual_start_date,
actual_comp_date,
-- kpi tracker
CASE
WHEN actual_start_date is null AND current_date < target_time THEN 'Not arrived on site yet'
WHEN actual_start_date is null AND current_date > target_time THEN 'FAIL (2)'
when actual_start_date <= target_time then 'Pass'
when actual_start_date > target_time then 'FAIL'
ELSE 'Overdue' END as Arrived_on_time_check,
-- start of correct target time SQL
case
when to_char(target_time, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') = 'Fri'
and floor((target_time - trunc(target_time)) * 24) >= 17
then target_time + 2 + 63/24
when floor((target_time - trunc(target_time)) * 24) >= 17
then target_time + 15/24
else target_time
end as target_time
from
(
select job_number, priority_code, job_entry_date, clock_start, site_code, actual_start_date, actual_comp_date,
CASE
WHEN PRIORITY_CODE IN ('GC01','GC02','GC03','GC04','GC05','GC06','GC07')
THEN
clock_start + case priority_code
when 'GC01' then 1
when 'GC02' then 2
when 'GC03' then 0.5
when 'GC04' then 1
when 'GC05' then 2
when 'GC06' then 4
when 'GC07' then 24
end / 24
ELSE TARGET_COMP_DATE END as target_time
from
(
select job_number, priority_code, job_entry_date, target_comp_date, site_code, actual_start_date, actual_comp_date,
case
when to_char(job_entry_date, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') = 'Fri'
and floor((job_entry_date - trunc(job_entry_date)) * 24) >= 17
then trunc(job_entry_date) + 80/24
when to_char(job_entry_date, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') = 'Sat'
then trunc(job_entry_date) + 56/24
when to_char(job_entry_date, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') = 'Sun'
or floor((job_entry_date - trunc(job_entry_date)) * 24) >= 17
then trunc(job_entry_date) + 32/24
when floor((job_entry_date - trunc(job_entry_date)) * 24) < 8
then trunc(job_entry_date) + 8/24
else job_entry_date
end as clock_start
from job
)
)
where
priority_code in ('GC01','GC02','GC03','GC04','GC05','GC06','GC07')
The code I want to add in is:
-- JOB KPI ATTRIBUTE LOOK UP IN GJOB TABLE
(SELECT attribute_value.attrib_value_name FROM attribute_value WHERE
attribute_value.attrib_type_code = 'GJOB'
AND attribute_value.attrib_value_code = job_type.job_type_code) as JOB_KPI,
-- JOB KPI PENALTY POINTS LOOK UP IN GJOB TABLE
(SELECT attribute_value.attrib_value_nom FROM attribute_value WHERE
attribute_value.attrib_type_code = 'GJOB'
AND attribute_value.attrib_value_code = job_type.job_type_code) as KPI_POINTS,
How do I add in the above code to the existing code without the error messages saying that it's an invalid identifier?

Case Expression and dates

I have the below case expression.
SELECT end_dt,
CASE WHEN TO_CHAR(A.END_DT,'MM/DD/YYYY') = '01/01/3000' THEN ''
WHEN TO_CHAR(A.END_DT,'MM/DD/YYYY') > TO_CHAR(SYSDATE,'MM/DD/YYYY') THEN TO_CHAR(SYSDATE,'MM/DD/YYYY')
ELSE TO_CHAR(A.END_DT,'MM/DD/YYYY')
END ENDDATE,
CASE WHEN TO_CHAR(A.END_DT,'YYYYMM') = '300001' THEN ''
WHEN TO_CHAR(A.END_DT,'YYYYMM') > TO_CHAR(SYSDATE,'YYYYMM') THEN TO_CHAR(SYSDATE,'YYYYMM')
ELSE TO_CHAR(A.END_DT,'YYYYMM')
END ENDDATE_YYYYMM,
CASE WHEN TO_CHAR(A.END_DT,'YYYY') = '3000' THEN ''
WHEN TO_CHAR(A.END_DT,'YYYY') > TO_CHAR(SYSDATE,'YYYY') THEN TO_CHAR(SYSDATE,'YYYY')
WHEN TO_CHAR(A.END_DT,'YYYY') > TO_CHAR(SYSDATE,'YYYY') THEN TO_CHAR(SYSDATE,'YYYY')
ELSE TO_CHAR(A.END_DT,'YYYY')
END ENDDATE_YYYY
FROM A
LEFT D ON A.ID = D.ID
WHERE 1=1
ORDER BY 1
OutPut:
End_dt ENDDATE ENDDATE_YYYYMM ENDDATE_YYYY
12/5/2012 14:33:24 01/05/2018 201212 2012
Expected output:
End_dt ENDDATE ENDDATE_YYYYMM ENDDATE_YYYY
12/5/2012 14:33:24 12/5/2012 201212 2012
Why do I get a result of 01/05/2018 and not 12/5/2012?
You're doing string comparisons on dates. Stop. Do date comparisons on dates.
The string '12/5/2012' is greater than the string '01/05/2018' because 1 is greater than 0. Oracle is performing a binary comparison.
SQL> select *
2 from dual
3 where '12/5/2012' > '01/05/2018';
D
-
X
Stop converting all your dates to strings and all will be well
SQL> select *
2 from dual
3 where date '2018-05-01' > date '2012-05-12';
D
-
X
Incidentally, the empty string '' is equivalent to NULL in Oracle.
Your query should look like:
CASE WHEN A.END_DT = date '3000-01-01' then null
WHEN A.END_DT > SYSDATE THEN TO_CHAR(SYSDATE,'MM/DD/YYYY')
ELSE TO_CHAR(A.END_DT,'MM/DD/YYYY')
END ENDDATE,
Don't do date comparisons as strings. It works for the other values, because you have the right format -- YYYYMMDD (or a partial piece of that).
Try this logic:
SELECT end_dt,
(CASE WHEN TO_CHAR(A.END_DT, 'MM/DD/YYYY') = '01/01/3000' THEN ''
WHEN A.END_DT > SYSDATE
THEN TO_CHAR(SYSDATE, 'MM/DD/YYYY')
ELSE TO_CHAR(A.END_DT, 'MM/DD/YYYY')
END) as ENDDATE,
(CASE WHEN TO_CHAR(A.END_DT, 'YYYYMM') = '300001' THEN ''
WHEN TO_CHAR(A.END_DT, 'YYYYMM') > TO_CHAR(SYSDATE, 'YYYYMM')
THEN TO_CHAR(SYSDATE,'YYYYMM')
ELSE TO_CHAR(A.END_DT,'YYYYMM')
END) as ENDDATE_YYYYMM,
(CASE WHEN TO_CHAR(A.END_DT, 'YYYY') = '3000' THEN ''
WHEN TO_CHAR(A.END_DT, 'YYYY') > TO_CHAR(SYSDATE, 'YYYY')
THEN TO_CHAR(SYSDATE, 'YYYY')
WHEN TO_CHAR(A.END_DT, 'YYYY') > TO_CHAR(SYSDATE,'YYYY')
THEN TO_CHAR(SYSDATE, 'YYYY')
ELSE TO_CHAR(A.END_DT, 'YYYY')
END) as ENDDATE_YYYY

SQL union query not returning both columns

I am trying to retrieve data from a database in a particular format to hook into a dashboard app. I need one column called "Import" with counts beneath it, and another called "Export" with relevant counts in that. I have the following query right now but it is only returning an Import column and I've verified there is relevant data to show as Export as well. Any ideas? Adding a screenshot of the result I'm getting...
SELECT count(*) as "Import", a.ship_id "Ship"
FROM SERVICE_EVENTS a JOIN CONTAINERS b ON a.eq_nbr = b.nbr
WHERE (
(to_char(sysdate, 'HH24') between '07' and '17' and a.performed between trunc(sysdate) + 7/24 and sysdate and category = 'I')
OR
(to_char(sysdate, 'HH24') between '18' and '23' and a.performed between trunc(sysdate) + 18/24 and sysdate and category = 'I')
OR
(to_char(sysdate, 'HH24') between '00' and '06' and a.performed between trunc(sysdate - 1) + 18/24 and sysdate and category = 'I')
)
AND a.TSERV_ID in ('LOAD', 'DISCHARGE') group by a.ship_id
UNION
SELECT count(*) as "Export", a.ship_id "Ship"
FROM SERVICE_EVENTS a JOIN CONTAINERS b ON a.eq_nbr = b.nbr
WHERE (
(to_char(sysdate, 'HH24') between '07' and '17' and a.performed between trunc(sysdate) + 7/24 and sysdate and category = 'E')
OR
(to_char(sysdate, 'HH24') between '18' and '23' and a.performed between trunc(sysdate) + 18/24 and sysdate and category = 'E')
OR
(to_char(sysdate, 'HH24') between '00' and '06' and a.performed between trunc(sysdate - 1) + 18/24 and sysdate and category = 'E')
)
AND a.TSERV_ID in ('LOAD', 'DISCHARGE') group by a.ship_id
;
You can do a conditional aggregation and simplify your query to this:
SELECT
a.ship_id AS Ship,
COUNT(CASE WHEN category = 'I' THEN 1 END) AS Import,
COUNT(CASE WHEN category = 'E' THEN 1 END) AS Export
FROM SERVICE_EVENTS a
JOIN CONTAINERS b
ON a.eq_nbr = b.nbr
WHERE
(
(to_char(sysdate, 'HH24') BETWEEN '07' AND '17' AND a.performed BETWEEN trunc(sysdate) + 7/24 AND sysdate)
OR (to_char(sysdate, 'HH24') BETWEEN '18' AND '23' AND a.performed BETWEEN trunc(sysdate) + 18/24 AND sysdate)
OR (to_char(sysdate, 'HH24') BETWEEN '00' AND '06' AND a.performed BETWEEN trunc(sysdate - 1) + 18/24 AND sysdate)
)
AND a.TSERV_ID in ('LOAD', 'DISCHARGE')
GROUP BY a.ship_id
You can explicitly select null as the column not being counted and do one more aggregation.
select max(Import) as Import, max(Export) as Export, Ship
from (
SELECT count(*) as "Import", null as "Export", a.ship_id "Ship"
FROM SERVICE_EVENTS a JOIN CONTAINERS b ON a.eq_nbr = b.nbr
WHERE (
(to_char(sysdate, 'HH24') between '07' and '17' and a.performed between trunc(sysdate) + 7/24 and sysdate and category = 'I')
OR
(to_char(sysdate, 'HH24') between '18' and '23' and a.performed between trunc(sysdate) + 18/24 and sysdate and category = 'I')
OR
(to_char(sysdate, 'HH24') between '00' and '06' and a.performed between trunc(sysdate - 1) + 18/24 and sysdate and category = 'I')
)
AND a.TSERV_ID in ('LOAD', 'DISCHARGE') group by a.ship_id
UNION
SELECT null as import, count(*) as "Export", a.ship_id "Ship"
FROM SERVICE_EVENTS a JOIN CONTAINERS b ON a.eq_nbr = b.nbr
WHERE (
(to_char(sysdate, 'HH24') between '07' and '17' and a.performed between trunc(sysdate) + 7/24 and sysdate and category = 'E')
OR
(to_char(sysdate, 'HH24') between '18' and '23' and a.performed between trunc(sysdate) + 18/24 and sysdate and category = 'E')
OR
(to_char(sysdate, 'HH24') between '00' and '06' and a.performed between trunc(sysdate - 1) + 18/24 and sysdate and category = 'E')
)
AND a.TSERV_ID in ('LOAD', 'DISCHARGE') group by a.ship_id
) t
group by Ship

Is there a function that will take an existing series of values in oracle SQL for Apex and will make a trendline based on those values?

I would like to create a trendline based on the values returned from a query. The logic needs to be applicable for other cases of placing a trendlines on series in Oracle PLSQL with Apex.
My series has X values that are dates and Y values that are time values. Here is my query that outputs my dates and Y values:
Select
null link,
(START_DATE) label,
Round(Avg(Run_TIME),3) "Average Length"
from
(Select job_id,
(Case :P4_DATE_CHOOSER
WHEN 'Daily' THEN trunc(start_time)
WHEN 'Weekly' THEN trunc(start_time, 'WW')
WHEN 'Monthly' THEN trunc(start_time, 'MM')
END) "START_DATE",
1440*(END_TIME - START_TIME) "RUN_TIME"
from apps.NI_INFA_ACTIVITY_LOG_V#util.world
WHERE
(:P4_JOB_SIZE_CHOOSER = 'Tiny' AND (1440*(END_TIME - START_TIME)) <= 1
OR
:P4_JOB_SIZE_CHOOSER = 'Small' AND (1440*(END_TIME - START_TIME)) > 1 AND
(1440*(END_TIME - START_TIME)) <= 5
OR
:P4_JOB_SIZE_CHOOSER = 'Medium' AND (1440*(END_TIME - START_TIME)) > 5 AND
(1440*(END_TIME - START_TIME)) <= 20
OR
:P4_JOB_SIZE_CHOOSER = 'Large' AND ((1440*(END_TIME - START_TIME)) > 20)
OR
:P4_JOB_SIZE_CHOOSER NOT IN('Small','Medium','Large','Tiny') AND (1440*(END_TIME - START_TIME)) > 0)
AND
(INFA_TYPE_CODE = 'WORKFLOW')
AND
OBJECT_NAME = :P4_WORKFLOWNAMES
AND
(
:P4_Data_Volume_Chooser = 'Small' AND SUCCESS_SOURCE_ROWS < 100
OR
:P4_Data_Volume_Chooser = 'Medium' AND SUCCESS_SOURCE_ROWS > 99 AND SUCCESS_SOURCE_ROWS < 10000
OR
:P4_Data_Volume_Chooser = 'Large' AND SUCCESS_SOURCE_ROWS > 9999
OR
:P4_Data_Volume_Chooser NOT IN ('Small','Medium','Large')
)
)
WHERE START_DATE BETWEEN
(Case :P4_DATE_CHOOSER
WHEN 'Daily' THEN trunc(to_date(:P4_BEGIN_DATES, 'MM-DD-YY'))
WHEN 'Weekly' THEN trunc(to_date(:P4_BEGIN_DATES, 'MM-DD-YY'), 'WW')
WHEN 'Monthly' THEN trunc(to_date(:P4_BEGIN_DATES, 'MM-DD-YY'), 'MM') END)
AND
(Case :P4_DATE_CHOOSER
WHEN 'Daily' THEN trunc(to_date(:P4_END_DATE, 'MM-DD-YY'))
WHEN 'Weekly' THEN trunc(to_date(:P4_END_DATE, 'MM-DD-YY'), 'WW')
WHEN 'Monthly' THEN trunc(to_date(:P4_END_DATE, 'MM-DD-YY'), 'MM') END)
group by START_DATE
order by START_DATE
;
Ideally, I'd be able to use my existing query as the source for a new subquery.