Case statement in query sub
Hi, I have two questions, here is my initial code:Select
CC.name_id_no
cc.discover_date
cc.cla_case_no
max (rl.year_of_incident) Non_Loss_Past_5
rl.timestamp
of cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc (cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc (cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and < 1095 (trunc (cc.discover_date)-(rl.year_of_incident))
- and (trunc (cc.discover_date) <>(rl.year_of_incident))
Group of cc.cla_case_no, name_id_no, cc.discover_date, rl.timestamp
Now a cla_case_no can map to several year_of_incident. I want only the cla_case_no that maps to the max year_of_incident, that is to say it should only be a single cla_case_no corresponding to the max year_of_incident.
To work around this problem, I did the following is not very effective and I hope that it can be improved:
Select distinct z.cla_case_no from)
Select
CC.name_id_no
cc.discover_date
cc.cla_case_no
max (rl.year_of_incident) Non_MW_Loss_Past_5
rl.timestamp
of cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc (cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc (cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and < 1095 (trunc (cc.discover_date)-(rl.year_of_incident))
- and (trunc (cc.discover_date) <>(rl.year_of_incident))
Group of cc.cla_case_no, name_id_no, cc.discover_date, rl.timestamp
) z
Now comes the second question: the above is actually a subquery that will link to a larger table via cla_case_no ccx
SELECT
This is to say, (select distinct z.cla_case_no of)
Select cc.name_id_no, cc.discover_date, cc.cla_case_no, max (rl.year_of_incident) Non_MW_Loss_Past_5, rl.timestamp
of cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc (cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc (cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and < 1095 (trunc (cc.discover_date)-(rl.year_of_incident))
- and (trunc (cc.discover_date) <>(rl.year_of_incident))
Group of cc.cla_case_no, name_id_no, cc.discover_date, rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5
Etc.
Now only some cc.cla_case_no the subquery to be match to the ccx_cla_case_no of the main table and the other entries will be void.
What I am asking, is that if the subquery returns a result that IS NOT NULL to return some ELSE 'Y' "n" instead of her ranges from cla_case_no entries (null) in the Non_MW_Loss_Past_5 column
Thank you!!!
Banner:
Oracle Database 11 g Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production."
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Hello
Looks like you have another copy of this issue:
Case statement and query sub
This probably isn't your fault, but you must mark the other copy as "Answered" right away, and then you only have to look for answers in one place.
885178 wrote:
... Now a cla_case_no can map to several year_of_incident. I want only the cla_case_no that maps to the max year_of_incident, that is to say it should only be a single cla_case_no corresponding to the max year_of_incident.
If you know there is only one, then you can use last, and you don't need GrOUP BY
To work around this problem, I did the following is not very effective and I hope that it can be improved:
Select distinct z.cla_case_no from)
Select
CC.name_id_no
cc.discover_date
cc.cla_case_no
max (rl.year_of_incident) Non_MW_Loss_Past_5
rl.timestamp
of cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident<>
and rl.type_of_loss<>
and rl.timestamp<>
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc (cc.discover_date)-(rl.year_of_incident))<>
-(trunc (cc.discover_date) <> (rl.year_of_incident))
Group of cc.cla_case_no, name_id_no, cc.discover_date, rl.timestamp
) z
Here's one way:
SELECT MIN (cla_case_no) KEEP (DENSE_RANK LAST ORDER BY r1.year_of_incident)
AS latest_cla_case_no
FROM cla_case cc
, rbn_loss rl
WHERE cc.name_id_no = rl.customer_no
AND rl.year_of_incident > TRUNC (cc.discover_date) - 1095
AND rl.year_of_incident < TRUNC (cc.discover_date)
AND rl.type_of_loss < 1000
AND rl.timestamp < TRUNC (cc.discover_date)
AND cc.question_class IN (20, 25)
;
If post you some examples of data (CREATE TABLE and INSERT statements) and outcomes from these data, I was able to test this.
Now comes the second question: the above is actually a subquery that will link to a larger table via cla_case_no ccx
SELECT
This is to say, (select distinct z.cla_case_no of)
Select cc.name_id_no, cc.discover_date, cc.cla_case_no, max (rl.year_of_incident) Non_MW_Loss_Past_5, rl.timestamp
of cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident<>
and rl.type_of_loss<>
and rl.timestamp<>
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc (cc.discover_date)-(rl.year_of_incident))<>
-(trunc (cc.discover_date) <> (rl.year_of_incident))
Group of cc.cla_case_no, name_id_no, cc.discover_date, rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5Etc.
Now only some cc.cla_case_no the subquery to be match to the ccx_cla_case_no of the main table and the other entries will be void.
What I am asking, is that if the subquery returns a result that IS NOT NULL to return some ELSE 'Y' "n" instead of her ranges from cla_case_no entries (null) in the Non_MW_Loss_Past_5 column
NVL2 (x, 'Y', 'N')
Returns 'Y' if x is NULL, and it returns "n" If x is not NULL. X can be a scalar subquery:
NVL2 ((SELECT ...), 'Y', 'N')
You can also use an EXISTS subquery:
CASE
WHEN EXISTS (SELECT ...)
THEN 'Y'
ELSE 'N'
END
Tags: Database
Similar Questions
-
Need to print the results of a query in a CASE statement
I want to print the results of a query in a CASE statement:
SELECT RUN_STATUS
Of
(select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)
END RUN_STATUS
of W_ETL_RUN_SDTL
where START_TS >
(sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e
The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.
If I execute this statement, it throws an error stating:
ORA-00937: not a single group group function
00937 00000 - 'not a single-group function.
* Cause:
* Action:
Error on line: 1 column: 96
How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.
Thanks in advance!
Hey guys,.
I found the solution:
SELECT
RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')
Of
(select check BOX WHEN COUNT (ROW_WID) = 0
THEN "NO JOB RAN.
END RUN_STATUS
of W_ETL_RUN_SDTL
where
START_TS > (select sysdate - XXAFL_MINUTES MINUTE))
where
RUN_STATUS is not null;
The output:
NO JOBS RAN AFTER 09:07:54
Thanks to you all!
-
Case statement in the SQL Query prompt dashboard
Hi Experts,
I use the following case statement to generate default values in the prompt dashboard based on a condition (the other guest-generated values). Below are two of the query I've tried and the syntax error. I tried all the possibilities (like giving apostrophes, double quotes, don't quote not etc.), but could not understand the question. Don't know what exactly I'm missing here.
Query 1:
SELECT
CASE
WHEN @{PRType} = monthly THEN 'Participant pay '. "" Amount of PayRate "="15000"
WHEN @{PRType} = daily THEN 'Participant pay '. "" Amount of PayRate "="650"
WHEN @{PRType} = hourly THEN 'Participant pay '. "" Amount of PayRate "="1"
ELSE ' 0'
END
OF 'PA-Participant pay. '
Query 2:
SELECT
CASE
WHEN @{PRType} = monthly THEN "15000"
WHEN @{PRType} = daily THEN "650"
@{PRType} = schedule THEN '1'
ELSE ' 0'
END
OF 'PA-Participant pay. '
This is the query that is generated in the log with error message file.
1 log message:
SELECT CASE WHEN Hourly = Monthly THEN "Participant Payroll"."Payrate Amount" = '15000' WHEN Hourly = Daily THEN "Participant Payroll"."Payrate Amount" = '650' WHEN Hourly = Hourly THEN "Participant Payroll"."Payrate Amount" = '1' ELSE '0' END FROM "PA-Participant Payroll"
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>=: Syntax error [nQSError: 26012]. (HY000)
Comment 2:
;CASE WHEN To_Char (Hourly) = 'Hourly' THEN 1 ELSE 0 END
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>(): syntax error [nQSError: 26012]. (HY000)
Sorry, I wasn't clear... you must always put this CASE statement in a valid SQL SELECT statement.
SELECT
CASE
When ' @{PRType}' = 'Monthly' THEN '15000'
When ' @{PRType}' = 'Daily' THEN '650'
ELSE '0' END
OF 'PA-Participant pay. '
-
Tuning - using the CASE statement in the WHERE clause of the query
Hi all
My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:
Query:
Description of the table:SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date, os.acctnum, os.avieworigin_refid, COUNT(1) cnt_articleview, SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm FROM TABLE1 os WHERE os.acctnum IS NOT NULL AND os.avieworigin_refid IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND CASE WHEN Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 END = 1 AND CASE WHEN Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' THEN 1 END = 1 GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
(Number of lines: approx. > amount 600 000 000)
Explain PlanName Null Type ------------------------------ -------- ------------ ARTICLEID NOT NULL NUMBER(20) USERKEY NUMBER(10) AVIEWORIGIN_REFID VARCHAR2(10) SUCCESS_IND VARCHAR2(2) ENTRY_CREATEDDATE DATE CREATED_BY VARCHAR2(10) FILENUMBER NUMBER(10) LINENUMBER NUMBER(10) ACCTNUM VARCHAR2(10) AUTOCOMPLETEDTERM NUMBER(2) REQUESTDATETIME VARCHAR2(19)
Published by: Chaitanya on June 9, 2011 02:44SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2224314832 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| |* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| ---------------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN 'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL' AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:47When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.
BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like? -
Use the CASE statement in a query of LOV
Hello
I wrote a select statement to be used in my list of values query, and it works fine when I run with SQL Developer. But when I put it in the LOV I get the LOV query is invalid error message. Here's the query I use:
If the CASE statement is the source of the problem?select case when nt.COMMON_NAME is not null then nt.COMMON_NAME || ' (' || nt.TAXON_NAME || ')' else nt.TAXON_NAME end display_species ,case when nt.COMMON_NAME is not null then nt.COMMON_NAME || ' (' || nt.TAXON_NAME || ')' else nt.TAXON_NAME end return_species FROM NBN_TAXON nt WHERE lower(nt.INPUT_CATEGORY) = decode(lower(:P312_TAXON_GROUP_ADD), 'fish', 'fishes', lower(:P312_TAXON_GROUP_ADD)) order by 1;
Hello
Try to remove the colon semi at the end.
See you soon
Ben
-
Help with making SQL query references to column aliases in the Case statement
I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:
SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,
CASE
WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
END acg_elig_comm_code
CASE
WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
END comm_code_description
OF spriden, rcresar, rcrapp1
WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')
OR rcresar_comm_code_02 ('268 ', '269', ' 270')
OR rcresar_comm_code_03 ('268 ', '269', ' 270')
OR rcresar_comm_code_04 ('268 ', '269', ' 270')
OR rcresar_comm_code_05 ('268 ', '269', ' 270')
OR rcresar_comm_code_06 ('268 ', '269', ' 270')
OR rcresar_comm_code_07 ('268 ', '269', ' 270')
OR rcresar_comm_code_08 ('268 ', '269', ' 270')
OR rcresar_comm_code_09 ('268 ', '269', ' 270')
OR rcresar_comm_code_10 ('268 ', '269', ' 270'))
Rcresar_aidy_code = & aidy_code
AND rcrapp1_aidy_code = rcresar_aidy_code
AND rcrapp1_curr_rec_ind = 'Y '.
AND rcrapp1_seq_no = rcresar_seq_no
AND spriden_pidm = rcresar_pidm
AND rcrapp1_pidm = rcresar_pidm
AND spriden_change_ind IS NULL
ORDER BY name
The second case statement is where I don't know exactly what it takes to get what I want.
Output should be like:
spriden_pidm name ID acg_elig_comm_code comm_code_description
«0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»
If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.
Published by: blackhole82 on January 20, 2009 09:20Hello
You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
You can set the alias in a subquery and then use it in a great query, like this:WITH sub_q AS ( SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name, CASE WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01 WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02 WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03 WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04 WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05 WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06 WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07 WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08 WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09 WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10 END acg_elig_comm_code -- Originally posted with , here (error) FROM spriden, rcresar, rcrapp1 WHERE (rcresar_comm_code_01 IN ('268','269','270') OR rcresar_comm_code_02 IN ('268','269','270') OR rcresar_comm_code_03 IN ('268','269','270') OR rcresar_comm_code_04 IN ('268','269','270') OR rcresar_comm_code_05 IN ('268','269','270') OR rcresar_comm_code_06 IN ('268','269','270') OR rcresar_comm_code_07 IN ('268','269','270') OR rcresar_comm_code_08 IN ('268','269','270') OR rcresar_comm_code_09 IN ('268','269','270') OR rcresar_comm_code_10 IN ('268','269','270')) AND rcresar_aidy_code = &aidy_code AND rcrapp1_aidy_code = rcresar_aidy_code AND rcrapp1_curr_rec_ind = 'Y' AND rcrapp1_seq_no = rcresar_seq_no AND spriden_pidm = rcresar_pidm AND rcrapp1_pidm = rcresar_pidm AND spriden_change_ind IS NULL ) SELECT sub_q.*, CASE WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course' WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB' WHEN acg_elig_comm_code = '270' THEN 'ACG possible' END comm_code_description FROM sub_q ORDER BY name
Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.
Published by: Frank Kulash, January 20, 2009 11:35
Syntax error has been corrected -
[8i] Case statement generates ORA-00932: inconsistent data types
Note: I work with a 8i database (Yes, he's old enough) and in this case, I have to deal with the types of data (e.g. TANK), I gives me to work with.
I am trying to calculate the amount of time product expected between manufacturing steps. As I found out though, sometimes I get a negative value then subtract the date the previous step ends the date of that ongoing stage begins. Since it is generally impossible to start a later stage before a previous step (imagine trying to screw a cap on a bottle that has no son Cup yet - it just may not happen), what I found is that sometimes two steps are started the same day and finished the same day (although not necessarily the day they started). This situation CAN occur when a person is two steps and connected to two steps at the same time, rather than log on to one, then the other. So what I need to do in these situations, is to replace the negative number by zero (I'll treat the stage as having no time-out).
Some examples of data:
(Note: the data set real is the result of a query and has about 200 K lines and columns more, but this should be representative enough to find a solution that works on my real application.)
Here's the query I use that sometimes returns negative values:CREATE TABLE steps ( item_id CHAR(25) , ord_nbr CHAR(10) , sub_nbr CHAR(3) , step_nbr CHAR(4) , start_date DATE , finish_date DATE ); INSERT INTO steps VALUES ('A','0000000001','001','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('A','0000000001','001','0020',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('A','0000000001','001','0030',TO_DATE('01/05/2011','mm/dd/yyyy'),TO_DATE('01/06/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('A','0000000001','002','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('A','0000000001','002','0020',TO_DATE('01/04/2011','mm/dd/yyyy'),TO_DATE('01/04/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('A','0000000001','002','0030',TO_DATE('01/06/2011','mm/dd/yyyy'),TO_DATE('01/07/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('B','0000000002','001','0005',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy')); INSERT INTO steps VALUES ('B','0000000002','001','0025',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));
These are the results I want to see:SELECT item_id , ord_nbr , sub_nbr , step_nbr , start_date - last_step_finished FROM ( SELECT s.* , LAG (s.finish_date) OVER ( PARTITION BY s.item_id , s.ord_nbr , s.sub_nbr ORDER BY s.step_nbr ) AS last_step_finished FROM steps s ); Returns: ITEM_ID ORD_NBR SUB STEP START_DATE-LAST_STEP_FINISHED ------------------------- ---------- --- ---- ----------------------------- A 0000000001 001 0010 A 0000000001 001 0020 -1.000 A 0000000001 001 0030 3.000 A 0000000001 002 0010 A 0000000001 002 0020 2.000 A 0000000001 002 0030 2.000 B 0000000002 001 0005 B 0000000002 001 0025 -2.000
And that's what I tried to do to get these results (comment pointed out which line has generated the error):ITEM_ID ORD_NBR SUB STEP START_DATE-LAST_STEP_FINISHED ------------------------- ---------- --- ---- ----------------------------- A 0000000001 001 0010 A 0000000001 001 0020 0.000 A 0000000001 001 0030 3.000 A 0000000001 002 0010 A 0000000001 002 0020 2.000 A 0000000001 002 0030 2.000 B 0000000002 001 0005 B 0000000002 001 0025 0.000
I know that I had errors in data type incompatible before with case statements in this particular 8i database, but I can't seem to understand why I'm getting one this time. I think it has something to do with the NULL value which may occur for last_step_finished. Also, if I change the case statement to:SELECT item_id , ord_nbr , sub_nbr , step_nbr , CASE WHEN start_dt - last_step_finished < 0 THEN 0 ELSE start_dt - last_step_finished -- THIS LINE GENERATES THE ORA-00932 ERROR END AS days_in_queue FROM ( SELECT s.* , LAG (s.finish_date) OVER ( PARTITION BY s.item_id , s.ord_nbr , s.sub_nbr ORDER BY s.step_nbr ) AS last_step_finished FROM steps s );
the query works fine. But, I'm not NULL, I 0. In the level of this request, I'll take the averages by item_id/step_nbr, and I want that 0 s to be included in the average. (NULL values, as far as I know, would be excluded. AVG(null,_1,_2) = AVG (1,2) = 1.5 NOT AVG (0,1,2) = 1)., CASE WHEN start_dt - last_step_finished < 0 THEN NULL ELSE start_dt - last_step_finished -- THIS LINE GENERATES THE ORA-00932 ERROR END
Thanks in advance!CASE requires that all expressions to be of the same type. Numeric data type code is 2, then that date produced different internal datatype 14:
SQL> select dump(1) a,dump(sysdate) b,dump(sysdate - (sysdate - 1)) c from dual; A B C ------------------ ----------------------------------- ------------------------------ Typ=2 Len=2: 193,2 Typ=13 Len=8: 219,7,6,27,13,7,50,0 Typ=14 Len=8: 1,0,0,0,0,0,0,0 SQL>
Case is supposed to process until the number, but it does not--a bug in some versions. Use explicit to_number:
, CASE WHEN start_dt - last_step_finished < 0 THEN 0 ELSE to_number(start_dt - last_step_finished) END AS days_in_queue
SY.
-
Join the results of a case statement
Hello everyone;
I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column. I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended. It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.
My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID). In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID. I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table. The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.
My current query:
SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.
dbin.snapshot_date, dbin.bin_id, dbin. ISBN,
CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID
Of ANOTHER sku. ProdID
END ProdIDMaster,
dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,
MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,
MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume
OF D_BIN_ITEMS dbin
SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU
LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)
WHERE REGION_ID = 1
AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID
ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU
LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)
WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr
ON ProdIDMaster = msr. ProdID
WHERE dbin. WAREHOUSE_ID = "PHL5."
AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')
AND dbin.bin_id like '% P-1-R '.
ORDER BY dbin.bin_id;
The error I receive:
Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier
ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement. If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.
Any help or advice would be greatly appreciated.
Post edited by: 8ea4344e-80ea-44e7-b8ac-d482be7245a7 I made a mistake when I posted the code. The ProdID_ID shown in the join should have been ProdIDMaster. I need to change this due to the fact that the name of the column used (which is what I based my alias on) may have been considered confidential information. All the other columns names remained unchanged.
Hello
8ea4344e-80EA-44e7-B8AC-d482be7245a7 wrote:
Hello everyone;
I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column. I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended. It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.
My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID). In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID. I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table. The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.
My current query:
SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.
dbin.snapshot_date, dbin.bin_id, dbin. ISBN,
CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID
Of ANOTHER sku. ProdID
END ProdIDMaster,
dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,
MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,
MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume
OF D_BIN_ITEMS dbin
SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU
LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)
WHERE REGION_ID = 1
AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID
ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU
LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)
WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr
ON ProdIDid_ID = msr. ProdID
WHERE dbin. WAREHOUSE_ID = "PHL5."
AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')
AND dbin.bin_id like '% P-1-R '.
ORDER BY dbin.bin_id;
The error I receive:
Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier
ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement. If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.
Any help or advice would be greatly appreciated.
Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.
Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Always say what version of Oracle you are using (for example, 11.2.0.2.0). Use "SELECT * VERSION of $ v;" to get it.
See the FAQ forum: Re: 2. How can I ask a question on the forums?
When you define an alias for column (such as PriodIDMaster) in the SELECT a query clause, you can use the alias in the ORDER byclause in this request, but this is the only place in this same query, where you can use it. If you want to use anywhere, like in a join condition, then calculate the new column in a subquery; then you can use it anywhere you want in a Super request.
I see expression BOX (not the same as a declarationBOX) where when ProdIDMaster is defined, but I do not see where it is used. Are you sure that you posted the code that is causing the problem?
-
I have problem with value NULL when the use CASE statement please help this question
I have problem with value NULL when the use CASE statement please help this question
Table: digital_val
SNO cl C2
1 San1 11
2 22 San2
Actual result: expected to A B
A B 11 22
11 NULL
22 NULL
query:
Select case when c1 = "san1" then c2,.
case If c1 = "san2" then c2 B
of digital_val
I'm more curious why, when you select 2 rows, you expect a result of row?
WITH digital_val
AS (SELECT 1 AS 'Sno', 'San1"C1, c2 FROM DUAL 11)
UNION ALL
2 SELECT AS 'Sno', 'San2"C1, c2 FROM DUAL 22)
SELECT CASE WHEN c1 is "San1" THEN END AS A c2.
CASE WHEN c1 = "San2" THEN END AS B c2
OF digital_val;
With no other input, if you select 2 rows, you get 2 rows. One of the other solutions use a max function, but is this really what you want, does not specify?
-
using a Case statement to display the values of column even as table headers
I have a database that has been set up kind of tricky, in that some tables are made up of columns that are field names and one link to another table that contain the data for these field... also names there ID displays as many lines instead of as a row of data. I would like to write a query to extract that information and display it as one line for each ID.
example: table 1
ID, name, itemresponse and itemcode, Description
Dee Jones Childrens Hospital 123 SITE location
123 dee Jones, Date of appointment next NEXTAPPT 22/04/2014
123 dee Jones was on bedrest NOSHOW reason do not show
I would like to have the display of data as a record on this same patient, instead of as 3 separate registers (with the Description column in table 1
Table 2
ID, name, place, Date of the next meeting, show no reason
123 dee Jones Childrens Hospital 22/04/2014 was the bed rest
I have included the code I worked on below my question, for me to get the desired results should I use the Case statement and it's the right way to do it below?
(SELECT
PAT.ID "PATIENT ID."
PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
PAT. "PATIENT DOB," DATE_OF_BIRTH
DS. Date 'Date of inpatients ',.
Dai. ITEM_CODE "Item Code",
Dai. DESCRIPTION "Description."
Siad. ITEM_RESPONSE,Max (CASE WHEN dai. ITEM_CODE IS "SITE" THEN DAI. Decription
ANOTHER NULL
END) AS "name of the hospital."
Max (CASE WHEN DAI.) ITEM_CODE IS 'NEXTAPPT' THEN DAI. ITEM_Description
ANOTHER NULL
END) AS 'next Appt Date. "
Max (CASE WHEN DAI.) ITEM_CODE IS "LASTDATE" THEN DAI. Description
ANOTHER NULL
END) AS 'last visit Date.
Max (CASE WHEN DAI.) ITEM_CODE IS 'NOSHOW' THEN DAI. Description
ANOTHER NULL
END) THAT "the reason has not shown".
Of
(PAT.ID "IDENTIFYING PATIENT",
PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
PAT. "PATIENT DOB," DATE_OF_BIRTH
DS. Date 'Date of inpatients ',.
Dai. ITEM_CODE "Item Code",
Dai. DESCRIPTION "Description."
Siad. ITEM_RESPONSEOf
dm_sessions Ds,
dm_session_assessments dsa,
DAS dm_admin_sections,
dm_session_assessment_items Siad,
Dai dm_admin_items,
Po Patient_Orders,
Inventory inv,
Patients_Table PAT
dm_admin_categories CAD
where dsa.session_Id = ds.session_Id
and PAT.ID = ds. Patient_ID
and dsa.excluded_assessment =' no
and dac.category_code = 'OPEN'and dsa.section_id = das.section_id
and das.category_id = dac.category_id
and das.section_code = 'northwest'
and dai.section_id = das.section_id
and dsai.item_id = dai.item_id
and dsai.session_assessment_Id = dsa.session_assessment_Id
and dsai.excluded =' no
- and Dai.ITEM_ID = Dsai.ITEM_ID
and Dai.ITEM_CODE IN ('SITE', 'NEXTAPPT', 'LASTDATE', 'NOSHOW')
and po.patient_ID = ds.patient_ID
and in. NDC_NO = inv. NDC_NO
and inv. TDRUG_ABBREV = in. DRUG_ABBREV
PAT.ID GROUP, PAT. FIRST | » '|| PAT. LAST, PAT. DATE_OF_BIRTH, ds. Date, dai. ITEM_CODE, dai. DESCRIPTION, Siad. ITEM_RESPONSE))Hello
DATE is not a very good name for a column. Use something like EVENT_DATE, that will not be confused with a keyword from Oracle, instead.
I don't see something like this column in the CREATE TABLE statement. He will always be the same value on all lines?
Here's a way to get the results you requested:
SELECT id
first name | ' ' || LastName AS name
Date of birth
MAX (CASE WHEN item_code = "NEXTAPPT", THEN item_response END) AS next_appointment,
MAX (CASE WHEN item_code = "LASTDATE" THEN item_response END) AS last_visit_date,
MAX (CASE WHEN item_code = "SITE" THEN item_response END) AS location
FROM mytable1
GROUP BY id, firstname, lastname, dob
;
Of course, I can't test it very well until you post INSERT statements for the sample data.
I guess that 2 or more lines of the entry have the same id, then they will necessarily be first name last name, the name and date of birth, too. No doubt they are standardized in your actual tables.
-
Select with case statement and a formula of the IIR
Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.
[code]
Select *.
Of
(
Select name, month, duration, volume, time_spent, date1, date2,.
-case when 'date' > = 'date1' then '1' other '0' end as departure,.
-case when 'date' < = "date2" then '1' other '0' as end ending
Of
(
Select *.
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
)
)
;
[/ code]
I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.
[code]
departure: IIf ([date] > = [date1], 1, 0)
[/ code]
[code]
ending: IIf ([date] < = [date2], 1, 0)
[/ code]
Any advice would be appreciated.
Hello
Whenever you have any questions, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Explain, using specific examples, how you get these results from these data.If the output depends on what anyone outside the application itself (for example, when it is run) and then include a few different examples and the results you want of each given the same sample data. For example, "if I run on November 19, 2013, while the results should be... because... but if I run between November 21 and November 27, then the results should be... because...". »
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
318f20b8-a3d0-4FB4-bb0f-73785250b7d4 wrote:
Hi, I was looking to get help regarding a statement writing box with a statement select statement all. I tried to reproduce a formula IIf access well that just wanted to check that the query I wrote is correct, any advice would be appreciated.
[code]
Select *.
Of
(
Select name, month, duration, volume, time_spent, date1, date2,.
-case when 'date' > = 'date1' then '1' other '0' end as departure,.
-case when "date."<= 'date2'="" then="" '1'="" else="" '0'="" end="" as="">=>
Of
(
Select *.
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
)
)
;
[/ code]
I want to know is where I have my ' select name, etc, I would change that to select * to make it easier instead of typing all the field_names outside, but I don't know how to do and also what follows is 2 IIF formulas from an access database for the start of the final case statements so I just wanted check I wrote it correctly.
[code]
departure: IIf([date]>=[date1],1,0)
[/ code]
[code]
ending: IIf ([date]<>
[/ code]
Any advice would be appreciated.
DATE is not a function of Oracle; in fact, it's a terrible name for a column or function, because it blends with the DATE data type.
In Oracle, the function SYSDATE returns the date and time, according to the clock on the database server. So, SYSDATE can return a value as November 19, 2013 06:33:15. If you want to midnight the same day (i.e., November 19, 2013 00:00:00) and then use TRUNC (SYSDATE).
String literals (for example the string which consists 5 characters d, a, t, e, and 1) go inside the single quotes. Numbers and the names of columns only.
If you want to include all the columns, more some calculated values, in a SELECT clause, then you must use a name table or alias before the *. (See select_2 below. To do this, assign the alias j to display online.)
Maybe you wanted to say something like:
Select *-it's select_1
de)
Select j. *-it's select_2
, case when SYSDATE > = date1 then 1 or 0 end as departure
, case when SYSDATE<= date2="" then="" 1="" else="" 0="" end="" as="">=>
de)
Select *-it's select_3
of call_1 cd
inner join call_2 ON cd.name = cl.queue cl
) j
)
;
As mentioned in a previous answer, you should be careful about the use of "SELECT *" in production code.
In select_3, it would be better if you explicitly listed the columns you need. It can improve efficiency and maintenance. In this request, queue and the name will be always the same, so you probably don't want to include both of them in the result set, in any case.
In select_1 and select_2, it is acceptable to use "SELECT *", assuming that select_3 is fixed.
Moreover, there is no point in using subqueries here. You can get the same results simply in a single query, without any subqueries.
-
Case statement in where clause
Hello
I have to write the following query using the value of the l_var variable in the case statement
How do I get there?
Select col3of the test
where col1 = "A".
and the case
When l_var = "Y' and col2 = 'B '.
When l_var = 'n' and col2 = 'C '.
end;
In your expression
case
When l_var = 'Y' and col2 = 'B '.
When l_var = ' only then col2 <> 'B '.
end;
you try to return a Boolean (True or False) value like 'then' value of the CASE statement.
Values Boolean are not an Oracle SQL data type, you cannot use the true/false result of col2 = 'B' as an expression. This is why it does not work.
It's even more simple as:
Select col3
of the test
where col1 = "A".
and ((l_var = «Y» et col2 = «B») or (l_var = ' no and col2 <> 'B'))
If you really want a CASE statement then:
Select col3
of the test
where col1 = "A".
and the CASE WHEN l_var = 'Y', THEN CASE WHEN col2 = 'B', 1 ELSE 0 END
WHEN l_var = ' no CASE THEN WHEN col2 <> 'B', 1 ELSE 0 END
END = 1
-
Hello everyone. I'm having a hell of a time trying to understand my nested case statement. It's pretty simple, but I always feel to get this error:
ORA-00937: not a single group group function
* 00937. 00000 - 'not a single-group function. "
Cause:
Action:
However, when I try to enter in a "group by" I get this error:
ORA-00979: not a GROUP BY expression
* 00979. 00000 - 'not a GROUP BY expression. "
Cause:
Action:
I don't know if there is something wrong with my nested case statement syntax, or miss me something more fundamental. This is my code:
I appreciate all help. Nice day.SELECT AE.EMP_ID, CASE WHEN EP.PHYSICAL_DATE IS NULL THEN CASE WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365) THEN 'NEEDS PHYSICAL' WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330) THEN 'COMING UP' ELSE 'No' END WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365) THEN 'NEEDS PHYSICAL' WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330) THEN 'COMING UP' ELSE 'No' END "Needs Physical?" FROM AP AE LEFT JOIN EMP_PHYSICAL EP ON AE.EMP_ID = EP.EMP_ID LEFT JOIN POSITION_OFFERED PO ON AE.EMP_ID = PO.EMP_ID LEFT JOIN EMP_CONTRACT EC ON AE.EMP_ID = EC.EMP_ID WHERE PO.ACTUAL_END IS NULL AND (EP.PHYSICAL = 1 OR EP.PHYSICAL IS NULL) AND :P71_EMP_ID = AE.EMP_ID;
AquaSELECT AE.EMP_ID,
CASE
WHEN EP.PHYSICAL_DATE IS NULL
THEN
CASE
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END "Needs Physical?"
FROM AP AE
LEFT JOIN EMP_PHYSICAL EP
ON AE.EMP_ID = EP.EMP_ID
LEFT JOIN POSITION_OFFERED PO
ON AE.EMP_ID = PO.EMP_ID
LEFT JOIN EMP_CONTRACT EC
ON AE.EMP_ID = EC.EMP_ID
WHERE PO.ACTUAL_END IS NULL
AND (EP.PHYSICAL = 1
OR EP.PHYSICAL IS NULL)
AND :P71_EMP_ID = AE.EMP_ID;
GROUP BY AE.EMP_ID,EP.PHYSICAL_DATE,EC.ORIGINAL_CONTRACT_START;Hi,
You need to add Group by clause at the end of the query i have added above.
-
How to aggregate categories Case statement to get a number of each
I would like to summarize this query, a County, or the sum of each category in the case statement, please help!
Here's a query I would like to change so he made a count (*) instead of list retail
Select distinct
partner, region, od. ORDER_AFFILIATE_NAME,
Oh.external_order_number,
Ain.get_g1 (queue_type) offers,
Case
When disp.category = 100 Then 'ORDER'
When disp.category = 200 Then 'ACCESS'
When disp.category = 300 Then 'DSL'
When disp.category = 600 Then 'IPTV'
"When disp.category = 700 Then'INTERNET"
When disp.category = 800 Then 'VOIP'
End up like product_category,
To_char(OH.created_ts, 'yyyy-mm-dd HH24:mi:ss') CREATE_DATE
-Case when ip.offer_type = "IPDSLAM" or instr (ip.display_name, "-d") > 0
THEN 'IP - LAN'
ELSE 'FTTN.
end as product_type
Case
When disp.state = 4 and disp.state = 9 or disp.state = 21 or 22 = disp.state then 'cancelled '.
When disp.state = 17 then "NRFC cancelled.
When disp.state = 7 Then 'incomplete '.
When disp.state = 3 or disp.state = 8, then "Finish".
When disp.state = 6 or disp.state = 10 and disp.state = 13 or disp.state = 14 then 'pending - other ".
When disp.state = 19 disp.state = 20 then "sent".
When disp.state = 21 or disp.state = 22 then "Cancelled - CSUS.
When disp.state = 23 or 24 = disp.state then 'Order Confirmation '.
When disp.state = 1 or disp.state = 2 or disp.state = 15 then "receipt".
Another 'other '.
End as STATE_desc
of AIN.impl_oh_order_header oh,.
Ain.impl_order_data od,
DISP AIN.sncr_order_curr_disp,
AIN.impl_package ip
where oh.created_ts between to_date ('2013-02-04', ' yyyy-mm-dd "")
and to_date ('2013-02-11', ' yyyy-mm-dd "")
and oh.order_type = 'COMMAND '.
and disp.category to (200, 300, 600, 700, 800)
and disp.state! = '5'
and uscs = 0
and disp.transaction_id = oh.transaction_id
and od. transaction_id = oh.transaction_id
and ip.transaction_id = oh.transaction_id
and ip.package_type = 'PACKAGE '.
and ip.parent_package_id is null
and ip.product_type = 'COMMAND '.See the answer in your other thread:
Help, please! Need to modify this Script to do a Count (*) -
I wonder if it's possible to put conditional case statements in a subquery in a pl sql view?
I have a sub request, and final statement is:
is it possible to do something like this conditionally includes the statement "AND"?AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1
WHEN id = 1( AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1)
When there is more conditions, better put everything in extra parentheses (because of the condition of GOLD):
...
AND (id != 1 OR (id = 1 AND EXISTS (SELECT NULL FROM steps ps WHERE ps.route = pr.id AND ps.step_type= 1)))
Maybe you are looking for
-
Satellite A200 webcam is used by another application
After a few seconds when I have turned on-camera web on my Satellite A200, it stop working and displaying the message "used by another application. Is there any officially recommended by TOSHIBA method to decide this problem?
-
where can I download xampp 1.8.3
I'm trying to resurrect a web server on Snow Leopard. Anyone know where I can get XAMPP version 1.8.3?
-
Automatic update FAIL - PC is turned off during use
Lenovo laptop. Full battery & powered by sector, Windows 7 RC Build 7100 I was busy doing banking Internet when suddenly restarted my laptop. The normal normal shutdown and restart, except that I didn't ask for restart. Because they don't a message t
-
Hi all, I have a question. Which is the best method (udp, tcp, http, using the pushRegistry...) to connect two blackberrys and set the communication with IP address? Thank you!
-
Hello I have renamed our CSA MC to windows server, but do not know how to recreate the agent kits so that they take into account the new name of the server (I think the name is included in the kits). How can I change this, and is there something that