SELECT in advanced SQL filter query

Hi all

I create a shared filter and I need to write a sql statement to a column. Can I use
in the Advanced SQL filter string functions. My sql query is:

Select distinct 'exchange rate '. "' Type ' of 'Credit'
where substr (rtrim ("exchange rate". "Type')(,-1,2) in (select distinct substr (rtrim (" "-year" "." ")))" (Name of the year"),-1, 2).
"Credit" where CURRENT_DATE between '-year '. " "Year Start Date ' and '-year '." Year-end Date")

there where, 'credit' = area name
'Exchange rate' and '-year "= table presentation.

I get the error message:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 27002] Close to: < select >: syntax error [nQSError: 26012]. (HY000)

I then tried a simple query in the Advanced SQL filter: "exchange rate". "" Type "= SELECT"exchange rate ". "' Type ' OF 'Credit'
which doesn't work anymore.

Can't debug the problem.

Thank you

I think that you will need to write SQL logic. You used SUBSTR and RTRIM which I didn't see in the list of functions in the responses. You must use the equivalent functions of responses such as substring and TrimLeading

Tags: Business Intelligence

Similar Questions

  • Separate function in Advance Sql

    Hello

    In OBIEE 10 g, I need to write a separate query for an attribute (City) in advance filter SQL.

    Please send me the syntax to use the distinct function in the Advanced SQL filter.

    City (SELECT DISTINCT CITY FROM SUBJECT AREA WHERE CONDITION) - filter advanced

  • Filter/query dataset in PL/SQL

    I have a set of data like this:

    ID status
    681Ok
    681Ok
    681ERROR
    721Ok
    721Ok
    750ERROR
    750ERROR
    750Ok

    The dataset is in PL/SQL, and it can be as a UDT type or table (see definitions below).

    I'm going to/filter to query this data set, such that I have a status for each code. If the same Id has both OK and ERROR, I should have recording with the error status. This is the result set, I need to get:

    ID status
    681ERROR
    721Ok
    750ERROR

    Could you please advice me on how to do so using PL/SQL?

    I would prefer a solution without the use of a global temporary table.

    Table type definition:

    TYPE TR_PIPELINE_BC_MDQ_STATUS IS MADE

    (

    ID BALANCING_CONTRACT. BALANCING_CONTRACT_ID % TYPE, NUMER - type

    STATUS DASHBOARD_STATUS_BC. STATUS_CODE % TYPE - VARCHAR2 (50)

    );

    TYPE TT_PIPELINE_BC_MDQ_STATUS IS TABLE OF THE TR_PIPELINE_BC_MDQ_STATUS;

    UDT:

    CREATE OR REPLACE TYPE UDT_R_PIPELINE_BC_MDQ_STATUS AS OBJECT

    (

    ID NUMBER,

    status VARCHAR2 (50)

    );

    CREATE OR REPLACE TYPE UDT_T_PIPELINE_BC_MDQ_STATUS

    AS THE UDT_R_PIPELINE_BC_MDQ_STATUS TABLE;

    ---------------------------------------------------------------------------------

    If I could do this as SQL, my query would be like this:

    SELECT DISTINCT id, status

    FROM table1

    Situation WHERE = "ERROR".

    UNION

    SELECT DISTINCT id, status

    FROM table1

    Situation WHERE = 'OK '.

    AND id NOT IN (SELECT DISTINCT ID

    FROM table1

    Situation WHERE = "ERROR");

    Table1 table:

    create table table1 (ID number, varchar2 (100));

    Insert sample data:

    Insert into TABLE1 (ID, STATUS) values (750, 'OK');

    Insert into TABLE1 (ID, STATUS) values (750, "ERROR");

    Insert into TABLE1 (ID, STATUS) values (750, "ERROR");

    Insert into TABLE1 (ID, STATUS) values (721, 'OK');

    Insert into TABLE1 (ID, STATUS) values (721, 'OK');

    Insert into TABLE1 (ID, STATUS) values (681, "ERROR");

    Insert into TABLE1 (ID, STATUS) values (681, 'OK');

    Insert into TABLE1 (ID, STATUS) values (681, 'OK');

    COMMIT;

    Hello

    In addition to the rp0428 answer: you can directly select a collection to help

    SELECT xy OF TABLE()

    Concerning

    Marcus

  • How to specify SQL custom querying the db with option to delete logical adapter

    Hi all

    I write a composite SOA application using JDeveloper SOA Suite 11.1.1.4 connection to a SQL Server database with the help of a Secretary of the poll the DB adapter with the logical delete option to send data to a BPEL process.

    I have requirements that go beyond what is supported in the UI JDeveloper for polling of the adaptor DB options, namely:
    * update several columns to mark each line read, and
    * specify different SQL to remove operation logic based on if bpel surveyed data processing was successful or not.
    A complicating factor is that the query contains two tables. Here is my complete use case:

    (1) mark will select data from two tables: for example 'headers' and 'details' simplified for this example:
    Table: headers
    HID - primary key
    name - plate
    status - "raw", "transformed" or "error".
    processedDate - null when the data is loaded, the DateTime current when the treatment of the line
    Table: Details
    HID - foreign key pointing header.hid
    attr - name attribute of data
    value - value of the attribute data

    2) there are a many relationship: 1 from detail lines to the header through the hidden columns. The adapter db SELECT the voting clerk must return results of an outer join consisting of line a header and the associated detail rows where header.status = 'no' and header.hid = details.hid. (This is supported by the UI Jdeveloper)

    (3) the survey data will be sent to be processed by a bpel process:
    (3.1) if the bpel treatment is successful, the logical delete operation (UPDATE) must set header.status = 'transformed' and header.processedDate = 'getdate() '.
    (3.2) if bpel treatment fails (for example hits a data error during the processing of the selected data) the logical delete operation (UPDATE) must be set to 'impossible' = header.status, header.processedDate = 'getdate()' and header.errorMsg = '{of the text returned by bpel}.

    Several parts of the #3 are not supported by the UI JDeveloper: update several columns to mark the addressed line, using getdate() to fill a value of one of these updates to the column, update of different operations based on the results of the BPEL, processing of the data (success or error) and using data from BPEL treating it as a value of these updates of column (error message).

    I found examples that describe the specification that is customized by using querying SQL Delete option to create a template and then modify the toplink files to specify custom select and update SQL to implement a logical deletion. (for example, http://dlimiter.wordpress.com/2009/11/05/advanced-logic-in-oracle-bpel-polling-database-adapter/ and http://myexperienceswithsoa.blogspot.com/2010/06/db-adapter-polling-tricks.html). But none of them match what I have in my project, in the first case because maybe because I use a newer version of JDeveloper and the second I think because in my case, two tables are involved.

    Any suggestion would be appreciated. Thank you, John

    Hi John,.

    You raised a good script.
    First of all, let me say that the purpose of the DB of the election operation, is to have an option to start the process of a DB table/view and not update several fields in a table (or have other complex manipulations on the table).
    Thus, when choose update a field in a record, after reading it, you "say" the engine not to question this record again. Of course, I guess you can find a solution/workaround for it, but I don't think that this is the way...

    The question now is what to do?
    You can have another DB adapter where you can update the data after you have completed the process. In this case, after reading the data (on the query operation) - updated the "transformed" for example = header.status and after processing the selected data update the rest fields.

    Hope it make sense for you.

    Arik

  • Change the sql filter code trade name

    All,

    one of my filters is a "Term" Advanced sql code "' Code word ' = VALUEOF (NQ_SESSION. CSA_Analysis_Term)
    When I add the filter to the report (add a filter) the user does not understand the code above,
    and I can't seem to find a way to add a name to make it more useful to users.

    anyone tried it with that

    Thank you

    I see your problem...

    When you have used this session variable in filters part you are able to see the session instead of the value variable last rite?

    You have guest of dashboard set to "Term". "' Term Code ' to the dashboard page?
    If so, why by default the session here filters variable part of the report? by default it prompt default dashboard section...

    just say guest is on the code term column in your report

    Published by: Kishore Guggilla, November 29, 2010 23:38

  • using select * in pl/sql

    Hello

    Yesterday knani mentioned that using SELECT * in PL/SQL is not a good idea. But I tried creating a table and different procedures to select all the columns using the * and by specifying the columns individually. Later, I changed the table and two procedures became invalid. Can give a simple example to demonstrate the behavior.

    At the moment I don't have Oracle in my PC for writing what I tried yesterday.

    See you soon,.

    Suri


    When I run the script after the 2nd time procedure test1 tracks, it fails with "PLS-00905: TEST1 object is invalid", while test2 works well every time.

    Feel free to try it yourself!

    create table boneist_test (col1, col2 varchar2 number (10));

    insert into boneist_test values (1, 'a');

    commit;

    Create procedure test1
    is
    number of v_num;
    v_var varchar2 (10);
    Start
    Select *.
    in v_num, v_var
    of boneist_test
    where rownum = 1;
    end Test1;
    /

    Create procedure test2
    is
    number of v_num;
    v_var varchar2 (10);
    Start
    Select col1, col2
    in v_num, v_var
    of boneist_test
    where rownum = 1;
    end test2;
    /

    Start
    Test1;
    end;
    /

    Start
    test2;
    end;
    /

    ALTER table boneist_test Add (col3 number);

    Start
    Test1;
    end;
    /

    Start
    test2;
    end;
    /

    drop table boneist_test;

    drop procedure test1;

    drop procedure test2;

  • SQL Dev 2.1 connected to a SQL Server query

    I use developer SQL to query the oracle db and the results of the query, if I right click I get the following options;

    Save grid under the report...
    Single record view...
    Number of lines...
    Find/highlight...
    Export data

    However, when I do this on a SQL Server I get only the following:

    Save the grid in the report...-c' is grayed out and cannot be used.
    Single record view...
    Number of lines...
    Find/highlight...

    I don't get the option to export, do anyone know why? or what I can do to get it?

    With SQL Developer 2.1.0 export feature has been removed for all with oracle database.

    In section 2.1.1 export feature works again if you need to export to SQL server, you should switch to 2.1.1.

  • Select ambiguous column in Sub query

    I get an error "ambiguous column" when I question using a sub select. Here's my query:

    Select *.
    (select
    c.custody_id,
    c.person_id,
    n.first_name,
    n.last_name,
    z.usms_number,
    c.start_date,
    c.end_date,
    c.district_office_id,
    CBC.custody_id,
    c.update_date,
    c.update_user_id
    Guard c,.
    custody_booking_pkg_components Radio-Canada,
    z_migrate_usms_number z,
    district_office do,
    District d,
    person p,
    n name
    where
    c.person_id = p.person_id and
    z.person_id = p.person_id and
    z.Ordinal = 1 and
    c.custody_id = cbc.custody_id (+) and
    p.name_id = n.name_id and
    do.district_id = d.district_id and
    c.district_office_id = do.district_office_id and
    d.district_id = 99 by c.update_date desc order)
    where rownum < = 10;

    I understand why "ambiguous column" average error, but I don't see which column is ambiguous. I ran the select sub by itself and it works correctly, but when combined with the external selection it fails.

    Hello

    You have two columns called custody_id.
    It is normal to have names duplicated in a query, but not in a table or view (and which includes a view online, you have).

    Type a unique name for each column.

  • How to have the filter query/dialogue opened when the report is launched in the workspace?

    Is it possible to have a default value for the report to prompt the user for a value of filter/query when the report is opened in the workspace? Currently, when a report is released, it will display data from the previous report instance.

    Not really.

    You could put a limit/filter on the query Section and then change to limit/filter Variable.

    You want to add the following code in the Scripts of the bqy

    "" "ActiveDocument.Sections ["Query"]." Process()

    where the query is the name of the Section application to deal with.

    When the file is opened, you should get the limit/filter dialog box and when the value is supplied the query will run and update the data for you

    hope this is what you need to do

    Wayne

  • Get the "selected lines" value after sql custom query in the database adapter

    We execute a custom query in a database adapter. With other technologies (JDBC, etc.) the result of a query produces not only a game but the number of lines selected results. For example, the output of the script of Oracle SQL Developer will display something like:

    9999 selected lines

    at the end of the output of the script.

    I would like to obtain this value for a BPEL process. Of course, I could run a 2nd interview whose where clause is identical to the first, but select count (*) instead. However, it is not only ineffective but (in rare circumstances in an active database) could be the problem.

    It is not obvious to the novice BPEL how to get the selected value and the result set row in an Invoke. Is this possible?

    Maybe it's not the only solution - but this is how I did in the past.

    After step to invoke the adapter, use a step of the having-right/copy to fill a variable of integer type BPEL using the xpath count function...






    That should affect the number of records returned by the query.

    I hope this helps.

    Rod.

    Published by: Tunnels of Rod on December 15, 2009 13:16

  • Help with an advanced SQL query

    I have a table with standard lengths of material. (tblStdLength)

    In another table are the lengths in stock to matter. (tblOnStock)

    I would like to match these two tables on the amount of the stock of standard lengths, you stock in the table.
    If the length is greater than the nearest standard length, the trail of the excess up to the closest standradlangd if there is a X 'CUP field.
    However, I have encountered a problem and cannot solve this...

    Ex:

    Material cable23 have 4 standard lengths in the tblStdLength Table:

    {code}

    Material StdLength
    ----------------------------------------------------
    Cable23 |     2000
    Cable23 |     4000
    Cable23 |     6000
    Cable23 |     8000

    Cable23 materials have the following lengths in stock in the tblOnStock Table:

    Factor important length TotalQty Cup
    -----------------------------------------------------------------------------------------------------------------------------
    Cable23 |     1     |     383.     383.
    Cable23 |     1     |     424.     424.
    Cable23 |     1     |     998.     998.
    Cable23 |     1     |     1000 |     1000 |
    Cable23 |     3     |     4000 |     12000 |     X
    Cable23 |     1     |     4234.     4234.     X

    {code}
    In this mode, the lengths of 12000 + 4000 must include in the calculation of the total stock of standard lengths.
    The answer should be 16000.
    4000, he gets to 4234. It has X on the field of 'Cut', then it round down to the nearest Stud.


    How can I be better? I hope that I have explained so you understand...

    Hello

    Did you mean this

    with tblStd as
    (
           select Material
                    , stdlength
                    , lead(stdlength) over (partition by material order by stdlength) hstdlength
                    from tblStdlength
    )
    select t.Material
             , sum(floor(s.totalqty/t.stdlength)*t.stdlength) tot_quantity
         from tblStd t, tblonstock s
                where t.material=s.material
                               and s.length >= t.stdlength
                               and (s.length< t.hstdlength or t.hstdlength is null)
                   and (s.cut = 'X' or s.length=t.stdlength)
                group by t.material
    

    Concerning
    Anurag

  • With the help of sql filter expression

    Hi Experts,

    I have a question using "sql expression" in the filters in the responses. Let's say I have a date filter and I wish that the value for this date as max (tablename.colname). Please tell me the syntax for this passage.

    Another issue is that I have a date guest data are updated every week we'll tell the data refreshed like this * 01/08/11, 08/08/11 and 15/08/11 *. Now, if I select the 08/08/11 it will display the data
    populated on * 08/08/11 * which is ok, but if I select * 09/08/11 to 14/08/11 * it only shows * 08/08/11 * data. Similarly, if the option * 16/08/11 or 16/09/11 * it should show the latest up-to-date data which is * 15/08/11 *.

    Thanks in advance.
    Chak

    OK, if that State is limited as of the last update when your selects a date in guest that is beyond / above the last refresh date.

    This can be a way to do as below:

    – Enter the last updated date in a variable repository. If this variable will always hold a value for the last date discount.
    -In guests, capture the date selected by the user in a variable of presentation and to apply the Sub statement in SQL advanced report.

    DateColumn = case when Timestamp ' @{RBAP} {2011-01-01 00:00:00}'<= valueof("lastrefdate")="" then="" timestamp="" '@{pvar}{2011-01-01="" 00:00:00}'="" else="" valueof("lastrefdate")="">

    RBAP following your presentation and lastRefDate var is your variable rep containing the last refresh date. What would this statement, if the user selects a date that is less than equal to the last refresh date, then report is filtered from this date. Otherwise, the report will be filtered by the value of the date of the last update.

    Thank you

  • Select Drop Down Menu recordset query.

    I'm looking to use a dynamic drop-down menu to query a Recordset... I use Colfusion to import a MS Access database that contains the following fields: 'Date template', 'Name', 'Points' and 'target '.  Whenever updates to the database, the field 'model' contains the date and time, the model has been run.  I figured out how to create a drop-down Dynamics using SELECT DISTINCT 'model date' and have also figured out how to create the dynamic recordset to display display the data 'Name', 'Points' and 'target '.

    I want the user to select the "Date of model" in the drop-down menu, press "submit" button and then have the appropriate 'Name', 'Points' and 'Target' data surveyed and below.

    The application must take the selection in the drop-down list of 'model date' and then query the fields 'name', 'points' and 'target' for this particular "date model.

    I admit that my knowledge of SQL and Coldfusion is not the best, but it seems that it is a fairly simple task and miss me just one or two pieces of gear and put everything.

    The database essentially looks like this:

    Date pattern... Name... Points of... Goal

    01/08/2010-08:00... DOE... 1, 250... 5.55%

    01/08/2010-08:00... DOE... 850... 2.35%

    01/08/2010-08:00... Bill Smith... 11, 832... -123,23%

    2010-08-02 09:02... DOE... 1, 323... 6.67%

    2010-08-02 09:02... DOE... 1: 001... 3.21%

    2010-08-02 09:02... Bill Smith... 10, 235... -110.26%


    The drop-down list shows only "model dates."

    01/08/2010-08:00

    02/08/2010 09:02

    For example, if on 01/08/2010 08:00 has been selected in the drop-down list, I want the following text is displayed:

    Name.................. Points of... Goal

    John Doe... 1, 250... 5.55%

    Jane Doe... 850.......................2.35%

    Bill Smith... 11, 832... -123,23%

    For any help or suggestion would be greatly appreciated!

    Thank you

    Mike

    My second paragraph speaks only to display the filtered data, so I guess that's what you're looking for, but not yet quite sure based on what are the other answers.

    But I'm on anyway-

    On your first page, note the instance name of your drop down menu, for example "ModelDate".  Make sure that it is in a form and set the form action on the page where you want to display your data, set the form POST action.

    On the results page, create a table with cells for each of the data items to display. Create a recordset that you can do in Simple mode. Allow to select all and the value of the fall of filter down to the database field that contains the Date of your model. In the box on the right, select "=". the next list dropdown selct "Variable form" and the name of the variable type in the name of the instance of falling down on the first page.

    I may not have the terminology right it's memory.

    On the data tab, expand your recordset and locate each of the database fields to display.  Drag each of them to the cell in the table on the page where you want it to display.  The cells in a table should be in a linear row.

    Now select the table row buy by selecting the TR tag in the tags just above the properties panel.  In the server behaviors tab, select the region of repetition and "All Records"

    Publish your pages and test!

  • SQL Count query - Assistance needed

    Hello

    Hoping someone can point me in the right direction. Here's the query I have so far. What I'm trying to do is to compare and add the names of the skills of individuals. My current query will count them, however, I need to take a step further where if the person has a name of "Spanish" skills can only which is counted and not their names other skills.

    Current query:

    WITH AS TBL1

    (SELECT

    TRIM (A.NWIE_ID) AS NWIE_ID,

    A.AGENT_NM,

    B.BUSINESS

    Of

    LIGHTHOUSE. IEX_AGENTS A JOIN

    LIGHTHOUSE. TBL_GEN_MU_BUSINESS B

    ON A.MU_ID = B.MU_ID

    WHERE B.BUSINESS IN ('PL_LEGACY'));

    TBL2 ACE

    (SELECT

    TRIM (C.USER_ID) AS USER_ID,

    TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,

    CASE

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 2) THEN "basic".

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 7) THEN "moderate."

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 10) THEN 'complex '.

    WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.

    Another null

    END AS SKILL_NM

    THE LIGHTHOUSE. C CFG_PERSON_SKILL_HIST

    )

    SELECT

    WEEKBEGINNING,

    SKILL_NM,

    COUNT (DISTINCT NWIE_ID) TOTAL_SKILLED

    Of

    TBL1,

    TBL2

    WHERE TBL1. NWIE_ID = TBL2. USER_ID

    AND SKILL_NM NOT IN ('NULL %')

    SKILL_NM GROUP, WEEKBEGINNING

    ORDER OF WEEKBEGINNING, SKILL_NM

    Create the Table data:

    CREATE TABLE IEX_AGENTS

    (

    AGENT_NM VARCHAR2 (20).

    NWIE_ID CHAR (8),

    NUMBER OF MU_ID (5)

    )

    CREATE TABLE TBL_GEN_MU_BUSINESS

    (

    BUSINESS VARCHAR2 (100),

    NUMBER OF MU_ID (5)

    )

    CREATE TABLE CFG_PERSON_SKILL_HIST

    (

    USER_ID VARCHAR2 (8).

    DATE OF ASOF_DT,

    SKILL_NM VARCHAR2 (64).

    NUMBER OF SKILL_LEVEL (10)

    )

    INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Marcelle, Athalie", "MARCELA1", 5)

    INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ('Lister, Laura", 'LISTERL3', 6)

    INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Purvis, Bradley", 'PURVIB1', 4)

    INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Cannon, Mark", "CANNON1", 4)

    INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 5)

    INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 6)

    INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 4)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacy', 1).

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacy', 7)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/9/2014 12:00 ',' PLSCLegacy', 7)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 3)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacySpanish', 6)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 2)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/19/2014 12:00 ',' PLSCLegacy', 10)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/19/2014 12:00 ',' PLSCLegacy', 2)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacy', 7)

    INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacySpanish', 7)

    Results of the current query:

    WEEKBEGINNINGSKILL_NMTOTAL_SKILLED
    07/03/2014 12:00:00 AMFoundational1
    07/03/2014 12:00:00 AMComplex1
    07/03/2014 12:00:00 AMModerate2
    07/03/2014 12:00:00 AMSpanish3
    14/03/2014 12:00:00 AMFoundational1
    14/03/2014 12:00:00 AMComplex2
    14/03/2014 12:00:00 AMModerate1
    14/03/2014 12:00:00 AMSpanish1

    Desired results:

    WEEKBEGINNINGSKILL_NMTOTAL_SKILLED
    07/03/2014 12:00:00 AMFoundational0
    07/03/2014 12:00:00 AMComplex0
    07/03/2014 12:00:00 AMModerate1
    07/03/2014 12:00:00 AMSpanish3
    14/03/2014 12:00:00 AMFoundational1
    14/03/2014 12:00:00 AMComplex2
    14/03/2014 12:00:00 AMModerate0
    14/03/2014 12:00:00 AMSpanish1

    WITH ACE TBL1)

    SELECT TRIM (A.NWIE_ID) AS NWIE_ID,

    A.AGENT_NM,

    B.BUSINESS

    OF IEX_AGENTS HAS

    JOIN THE

    TBL_GEN_MU_BUSINESS B

    ON A.MU_ID = B.MU_ID

    WHERE B.BUSINESS IN ("PL_LEGACY")

    ),

    (ACE TBL2)

    SELECT USER_ID, TRIM (C.USER_ID)

    TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,

    CASE

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 2)="" then="">

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 7)="" then ="">

    WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 10)="" then ="">

    WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.

    END AS SKILL_NM

    OF CFG_PERSON_SKILL_HIST C

    ),

    (AS TBL3)

    SELECT USER_ID,

    WEEKBEGINNING,

    SKILL_NM,

    COUNT)

    SKILL_NM SEPARATE CASE

    WHEN 'Spanish', 1

    END

    ) HAS_SPANISH OVER (PARTITION BY USER_ID, WEEKBEGINNING)

    FOR TBL2

    )

    SELECT WEEKBEGINNING,

    SKILL_NM,

    COUNT)

    SEPARATE CASE

    WHEN HAS_SPANISH = 0 THEN NWIE_ID

    WHEN SKILL_NM = "Spanish" THEN NWIE_ID

    END

    ) TOTAL_SKILLED

    FROM TBL1;

    TBL3

    WHERE TBL1. NWIE_ID = TBL3. USER_ID

    AND SKILL_NM NOT IN ('NULL %')

    SKILL_NM GROUP,

    WEEKBEGINNING

    ORDER OF WEEKBEGINNING,

    SKILL_NM

    /

    WEEKBEGINNING SKILL_NM TOTAL_SKILLED
    ---------------------- ------------ -------------
    03/03/2014 12:00:00 am founders 0
    03/03/2014 moderate from 12:00:00 am 0
    03/03/2014 12:00:00 am 2 Spanish
    17/03/2014 12:00:00 am complex 1
    17/03/2014 12:00:00 am basic 1
    17/03/2014 12:00:00 am Spanish 1

    6 selected lines.

    SQL >

    SY.

  • Delay and advance SQL / another option for conditional use

    Hi all SQL gurus

    I want to shoot the previous record and subtract status_date the two folder to find the number of # of days.

    Create table temp (o_id number, r_id number status_date date, status varchar2 30()));

    Examples of data

    I_ID r_id status_date State

    33493 308963 16 March 12 incarcerated

    33493 308943 26 - SEP - 11 City/County Jail

    33493 306529 15 December 09 Active

    33493 295327 25-NOV-09 City/County Jail

    33493 293630 30 July 09 Active

    33493 292828 30 July 09 Active

    33493 292830 30 July 09 Active

    33493 292826 21 May 09 City/County Jail

    33493 291854 5 May 09 Active

    Select I_ID, status_date, gal (R_ID, 1) (order status_date)

    de TEMP where I_IDin (33493) and status_date > = November 1, 2007

    and temp. Status = 'Active ';

    Logical, I'm trying to accomplish is to find the status_date of incarceration and find the last asset , status_date and subtract these dates.

    for example, 16-mar-12 less 15 December 09

    Thanks for the help...

    Pls help me to think about that...

    Hello

    This certainly looks like a job for the functions analytical, but LAG maybe not the best choice if you have several lines "incarcerated".  You might be better of LAST_VALUE or MAX, like this:

    WITH got_prev_active_status_date AS

    (

    SELECT TEMP *- or the list of all the columns you need

    MAX (CASE

    Status WHEN = 'Active'.

    THEN status_date

    END

    ) OVER (PARTITION BY i_id - just guessing

    ORDER BY status_date

    ) AS prev_active_status_date

    TEMP

    Situation WHERE IN ('Active', "imprisoned")

    )

    SELECT p - or the list of all the columns you need

    , status_date - prev_active_status_date AS days_active

    OF got_prev_active_status_date

    Situation WHERE = "incarcerated";

    I hope that answers your question.
    If not, 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.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    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

Maybe you are looking for