Multi sub-select query help

Hello:
I need to write a query which identifies the patients who exist in the master table for a given organization and trait and do not exist in the final table.
For example, for organization 499 and trait 43926, I have a total of 119 patients. After some processing, out of these 119 patients, only 106 patients get inserted into the final_traits table.
This leaves us with a difference of 13 patients. I want a query that will give me this list of 13 patients.
In order to achieve this, I need to use three tables:
1.     Master_traits which contains the entire patient population. The field needed from this table is dwkey_patient.
2.     Patient which contains the demographic info. The three fields needed from this table are dwkey_patient, patient_key, and name.
3.     Final_traits which contains the detail trait info. The field needed from here is patient_key.
To retrieve the 119 patients along with their names, the first join needs to be between “master_traits” and “patient” using the dwkey_patient field.
From these 119 patients, to determine which ones did NOT get inserted into the final_traits table, the second join will be between “patient” and “final_traits” using the patient_key field. This should give me 13 patients.
So far, I have the portion of the query which gives me the total population of 119.
select a.dwkey_patient, b.patient_key, b.name
from master_traits a, patient b
where a.dwkey_patient = b.dwkey_patient
and a.dwkey_org = 499
and a.dwkey_approval > 0
and a.dwkey_traittype = 43926
and a.out_of_range is null
order by dwkey_patient asc;
[/code]
I am having a tough time getting the second portion of the query to show me the 13 patients who were not inserted.
Can someone help?
Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Well,
It works for me...
MHO%xe> with master_traits as
  2  ( select 1234 dwkey_patient from dual union all
  3  select 2345 from dual union all
  4  select 3456 from dual union all
  5  select 4567 from dual union all
  6  select 5678 from dual
  7  )
  8  , patient as
  9  ( select 1234 dwkey_patient, 900 patient_key, 'smith' name from dual union all
10   select 2345, 901, 'jones' name from dual union all
11   select 3456, 902, 'murphy' name from dual union all
12   select 4567, 903, 'brown' name from dual union all
13   select 5678, 904, 'miller' name from dual
14   )
15  , final_traits as
16  ( select 900 patient_key from dual union all
17  select 901 from dual union all
18  select 903 from dual
19  ) -- actual query starts here:
20  select a.dwkey_patient, b.patient_key, b.name
21  from   master_traits a
22     ,   patient b
23     ,   final_traits c
24   where a.dwkey_patient = b.dwkey_patient
25  --   and a.dwkey_org = 499
26  --   and a.dwkey_approval > 0
27  --   and a.dwkey_traittype = 43926
28  --   and a.out_of_range is null
29     and b.patient_key = c.patient_key(+)
30     and c.patient_key is null
31  ;
DWKEY_PATIENT PATIENT_KEY NAME
         5678         904 miller
         3456         902 murphySo, you might need to adjust your WHERE clause I commented out in above example...
MHO%xe> with master_traits as
  2  ( select 1234 dwkey_patient from dual union all
  3  select 2345 from dual union all
  4  select 3456 from dual union all
  5  select 4567 from dual union all
  6  select 5678 from dual
  7  )
  8  , patient as
  9  ( select 1234 dwkey_patient, 900 patient_key, 'smith' name from dual union all
10   select 2345, 901, 'jones' name from dual union all
11   select 3456, 902, 'murphy' name from dual union all
12   select 4567, 903, 'brown' name from dual union all
13   select 5678, 904, 'miller' name from dual
14   )
15  , final_traits as
16  ( select 900 patient_key from dual union all
17  select 901 from dual union all
18  select 903 from dual
19  )
20  select a.dwkey_patient, b.patient_key, b.name
21    from master_traits a, patient b
22   where a.dwkey_patient = b.dwkey_patient
23  --   and a.dwkey_org = 499
24  --   and a.dwkey_approval > 0
25  --   and a.dwkey_traittype = 43926
26  --   and a.out_of_range is null
27     and not exists ( select null
28                        from final_traits c
29                       where c.patient_key =  b.patient_key )
30  ;
DWKEY_PATIENT PATIENT_KEY NAME
         5678         904 miller
         3456         902 murphyWorks too (ofcourse)
Edited by: hoek on Jun 4, 2009 8:37 PM

Similar Messages

  • Sub select query Help

    I have to do a task of finding records which matches the following logic.
    My table has PID varchar(15), Amount varchar (50),Status varchar(20) columns.
    Each PID can go thru changes in a period of time, in my case i dont have a data range I just have a flatfile which consists of three types of PID`s
    123456 = Original_PID, Reversal =123456R1,Adjustment= 123456A1.
    Basically What I am trying to find out if there are any original PID`s which has a Reversal or an Adjustment.
    here`s the code I have started on... Can someone help me get it finished?
    select R1. pid,a1.pid,org.pid from (
    select SUBSTRING(Pid,1,11)as Original_PID, status, paid_amount as Amount from dbo.Q2STATUS)org
    inner join (select SUBSTRING(Pid,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
    where SUBSTRING(Pid,12,2) ='R1')r1 on r1.pid=org.pid
    inner join (select SUBSTRING(claim_id,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
    where SUBSTRING(Pid,12,2) ='A1')A1 on a1.Pid=org.PID
    FM

    Hi,
    Please check following item
    It uses a
    SQL string function, please create it first
    create table Q2STATUS (Pid nvarchar(200), Status varchar(20), paid_amount int)
    insert into Q2STATUS select '123456 = Original_PID, Reversal =123456R1, Adjustment= 123456A1',NULL,250
    with cte2 as (
    select rn = row_number() over (order by pid), * from Q2STATUS
    ), cte as (
    select cte2.*, s.id typeid, v.*
    from cte2
    cross apply dbo.split(cte2.Pid, ',') s
    cross apply dbo.split(s.val, '=') v
    ), cte3 as (
    select
    rn, pid, status, paid_amount, max(pidtype) pidtype, max(pidval) pidval
    from (
    select
    rn, Pid, status, paid_amount, typeid,
    case when (typeid = 1 and id = 2) or (typeid <> 1 and id = 1) then ltrim(rtrim(val)) else null end as pidtype,
    case when (typeid = 1 and id = 1) or (typeid <> 1 and id = 2) then ltrim(rtrim(val)) else null end as pidval
    from cte
    ) g
    group by rn, pid, status, paid_amount, typeid
    select
    cte2.rn, cte2.pid,
    cte3.pidval as 'Original_PID',
    cte4.pidval as 'Reversal',
    cte5.pidval as 'Adjustment'
    from cte2
    left join cte3 on cte3.rn = cte2.rn and pidtype = 'Original_PID'
    left join cte3 as cte4 on cte4.rn = cte2.rn and cte4.pidtype = 'Reversal'
    left join cte3 as cte5 on cte5.rn = cte2.rn and cte5.pidtype = 'Adjustment'
    Here is the result,
    Please note that I have used
    SQL CTE expressions a lot in the SQL query to prevent usage of sub-select and temp tables.
    There is also a
    SQL ROW_NUMBER() function used in the first SELECT statement to distinquish all items from each other instead of using the PID column value. Perhaps you have already an ID key column, you can use it too
    SQL Server, SQL Server 2012 Denali and T-SQL Tutorials

  • Select query help for Sales order

    Hi Experts,
    I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
    Any help is appreciated. Expecting code samples....Thanks
    Thanks
    Ricky

    hi,
    do like this,
    write a select query for vbak and vbuk as follows.
    delivery status field is <b>lfstk</b> from <b>vbuk</b>,
    and relation field is <b>vbeln</b> from the both the tables.
    reward points if useful,
    regards,
    seshu.

  • SQL SELECT Query Help   ..Please its very Urgent!!

    Hi All,
    I am having Oracle Database whice is storing 1000's of records daily.
    I need to select some information based on date and time.
    I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    If any one helps me in this regard iam very thank full to them.Its very urgent for me.
    Thanks

    Hi m7nra,
    I used the query as
    SELECT * FROM table
    WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
    its giving DATE FORMAT NOT RECOGNIZED error.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    Please help me to find a full query beacuse iam very new to Oracle.
    Thanks,
    S R Mannava

  • Stuck on CONNECT_BY ... PRIOR statement / sub-select Query

    I am trying to generate a list of customisations made to our eBusiness system.
    I'm using this example as a starting point:
    SELECT *
       FROM applsys.jdr_paths jp1
      WHERE UPPER(jp1.path_name) = 'CUSTOMIZATIONS'
        AND jp1.path_docid BETWEEN 18000 AND 18700;
    _NAME                                                    PATH_DOCID PATH_OWNER_DOCID PATH_TYPE                        PATH_SEQ PATH_XML_V PATH_XML_E CREATED_BY                     CREATION_ LAST_UPDATED_BY                LAST_UPDA LAST_UPDATE_LOGIN
    customizations                                                18479             1650 PACKAGE                                -1                       1                              24-SEP-05 1                              24-SEP-05 1
    customizations                                                18665            18663 PACKAGE                                -1                       1                              24-SEP-05 1                              24-SEP-05 1
    customizations                                                18010            18009 PACKAGE                                -1                       1                              24-SEP-05 1                              24-SEP-05 1I can then use this to extract the full path - for example, using the example above, the "PATH_OWNER_DOCID" = 18663:
    SELECT     LEVEL
             , SYS_CONNECT_BY_PATH(p.path_name, '/') PATH
             , p.path_docid
          FROM (SELECT jp.path_name
                     , jp.path_seq
                     , jp.path_docid
                     , jp.path_owner_docid
                  FROM applsys.jdr_paths jp) p
    CONNECT BY path_docid = PRIOR path_owner_docid
    START WITH p.path_docid = 18665;
    LEVEL     PATH                                                                  PATH_DOCID
    1     /customizations                                                          18665     
    2     /customizations/webui                                                  18663     
    3     /customizations/webui/pagesetup                                          18661     
    4     /customizations/webui/pagesetup/printmgmt                          18660     
    5     /customizations/webui/pagesetup/printmgmt/bpa                          10174     
    6     /customizations/webui/pagesetup/printmgmt/bpa/ar                  10173     
    7     /customizations/webui/pagesetup/printmgmt/bpa/ar/apps                  2     
    8     /customizations/webui/pagesetup/printmgmt/bpa/ar/apps/oracle          1What I'd really like to do is to include the bottom most path (i.e. the most detailed, full path (path_docid = 1 in the e.g. above) in the first SQL statement.
    That way, against each customisation, listed via this:
    SELECT *
       FROM applsys.jdr_paths jp1
      WHERE UPPER(jp1.path_name) = 'CUSTOMIZATIONS'
        AND jp1.path_docid BETWEEN 18000 AND 18700;I would like to include, possibly via a sub-select, the full path of the customisation - not all of the other lines leading up to the full path, just the full path itself.
    But I can't work out how to combine the 2 SQLs, assuming it can be done at all.
    Any advice much appreciated.
    Thanks!

    If understand your question right... Just a MAX would work.
    select (SYS_CONNECT_BY_PATH(object_name, '/'))
    from
    select object_name, rownum lv
           from all_objects
       where rownum <= 5
       ) t
        START WITH lv = 1
       CONNECT BY PRIOR lv = lv - 1
    (SYS_CONNECT_BY_PATH(OBJECT_NAME,'/'))                                         
    /WRH$_SERVICE_WAIT_CLASS_PK                                                    
    /WRH$_SERVICE_WAIT_CLASS_PK/WRH$_SERVICE_WAIT_CLASS                            
    /WRH$_SERVICE_WAIT_CLASS_PK/WRH$_SERVICE_WAIT_CLASS/WRH$_SYS_TIME_MODEL_PK     
    /WRH$_SERVICE_WAIT_CLASS_PK/WRH$_SERVICE_WAIT_CLASS/WRH$_SYS_TIME_MODEL_PK/WRH$_SYS_TIME_MODEL
    /WRH$_SERVICE_WAIT_CLASS_PK/WRH$_SERVICE_WAIT_CLASS/WRH$_SYS_TIME_MODEL_PK/WRH$_SYS_TIME_MODEL/WRH$_OSSTAT_PK
    5 rows selected.
    select max(SYS_CONNECT_BY_PATH(object_name, '/'))
    from
    select object_name, rownum lv
           from all_objects
       where rownum <= 5
       ) t
        START WITH lv = 1
       CONNECT BY PRIOR lv = lv - 1
    MAX(SYS_CONNECT_BY_PATH(OBJECT_NAME,'/'))                                      
    /WRH$_SERVICE_WAIT_CLASS_PK/WRH$_SERVICE_WAIT_CLASS/WRH$_SYS_TIME_MODEL_PK/WRH$_SYS_TIME_MODEL/WRH$_OSSTAT_PK
    1 row selected.vr
    Sudhakar B.

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • SQL select query help

    I know this is a SQL question but I can't seem to figure this
    out. The below SQL query will run without error however it will
    output the company_name for every row which I dont want.
    So basicly it currently outputs like this now:
    company_name - apple
    company_name - dell
    BUT want it to output like this:
    company_name - apple,dell
    MY CURRENT QUERY:
    SELECT d.disputeid, t.company_name, t.tlid, t.type,
    l.description
    FROM member_disputes d, member_tradeline t, letters l
    WHERE d.fk_tlid = t.tlid
    AND d.fk_letterid = l.letterid
    AND d.fk_memberid = #GetAuthUser()#
    Any help much appreciated

    quote:
    Originally posted by:
    LionelR
    I know this is a SQL question but I can't seem to figure this
    out. The below SQL query will run without error however it will
    output the company_name for every row which I dont want.
    So basicly it currently outputs like this now:
    company_name - apple
    company_name - dell
    BUT want it to output like this:
    company_name - apple,dell
    MY CURRENT QUERY:
    SELECT d.disputeid, t.company_name, t.tlid, t.type,
    l.description
    FROM member_disputes d, member_tradeline t, letters l
    WHERE d.fk_tlid = t.tlid
    AND d.fk_letterid = l.letterid
    AND d.fk_memberid = #GetAuthUser()#
    Any help much appreciated
    Suddenly a light bulb illuminated over my head.
    <cfouput>
    company_name - #ValueList(yourquery.company_name)#
    </cfoutput>
    If that doesn't work, either change this, "t.company_name" to
    "company_name" or "t.company_name as company_name".
    I can't believe none of us thought of this earlier.

  • Problem with select query:help

    SELECT url,SUM(data_received) xyz FROM logs GROUP BY url ORDER BY xyz desc
    when i triedthe above query in the worksheet it works fine but when i write same query in code i get this error.
    myjsp page has this code.
    <%while (rset.next())
    out.println("<tr>");
    out.println("<td>" +
    rset.getString(1) + "</td><td>" +
    rset.getInt(2) + "</td><td> " +
    "</td>");
    out.println("<tr>");
    %>
    This is the error
    500 Internal Server Error
    java.sql.SQLException: Invalid column name at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3201) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1880) at oracle.jdbc.driver.ScrollableResultSet.findColumn(ScrollableResultSet.java:1308) at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1618) at list_action._jspService(_list__action.java:67) [list_action.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.0.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:60) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:416) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:478) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:401) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)
    please help

    This is not the proper forum....
    Post this thread to
    Java Server Pages (JSP)
    Greetings...
    Sim

  • Very slow Sub Select Query

    Oracle Version 9.2.0.7.0
    Sorry to ask what is probably a stupid question that only serves to highlight how useless my SQL is!
    I have this SQL which counts total requisition lines, and then counts how many of those lines have converted to Sales Orders:
    SELECT prha.segment1
         , (SELECT COUNT(*)
              FROM po.po_requisition_lines_all prla
             WHERE prla.requisition_header_id = prha.requisition_header_id)
                                                                      req_line_ct
         , (SELECT COUNT(*)
              FROM po.po_requisition_lines_all prla
                 , ont.oe_order_lines_all sol
             WHERE prla.requisition_line_id = sol.source_document_line_id
               AND prla.requisition_header_id = prha.requisition_header_id)
                                                                       so_line_ct
      FROM po.po_requisition_headers_all prha
    WHERE  prha.creation_date >= '03-JUL-2008';The SQL works, but it is really, really slow. Is that just because it is running through lots and lots of data?
    If I comment out the 2nd Count SELECT, it runs immediately. Perhaps it is so slow because the join between the po_requisition_lines_all and the oe_order_lines_all table is not via primary keys. Also, there is not an index on the oe_order_lines_all table related to the source_document_line_id field.
    I'm sorry I haven't provided the full table designs for the tables involved - but the primary keys joining the requisition tables = via the requisition_headers_all table, and the join via the po_requisition_lines_all and the oe_order_lines_all table is not via a primary key or an index.
    Sorry once again, for probably talking nonsense.

    Please note this is a untested code as you didn't provide any of the required information like
    a) Test Data
    b) Relationship between the tables
    You could try something like this. But as already @someoneelse suggested it is definitely worth reading the link.
    select prha.segment1, count(case when prla.requisition_header_id is not null then 1 end) req_line_ct,
    count(case when sol.source_document_line_id is not null then 1 end) so_line_ct
    from
    po.po_requisition_header_all prha,
    po.po_requisition_lines_all prla,
    ont.oe_order_lines_all sol
    where
    prha.creation_date >= to_date('03.07.2008','dd.mm.yyyy')
    and
    prha.requisition_header_id = prla.requisition_header_id (+)
    and
    prla.requsition_line_id = sol.source_document_line_id (+)
    group by prha.segment1;Regards
    Raj

  • SQLPLUS newbie: SELECT query help

    Hi:
    The following line prints all the records I am expecting to see.
    select d.device_id,c.ORG_NAME
    from device d, customer c
    where d.device_type in ('DOS') and d.cust_id = c.cust_id;But the following line doesn't print any records since the there are no entries in contact table. I want this to print all the records that were printed for the above statement and if available co.FIRSTNAME as well.
    select d.device_id,c.ORG_NAME,co.FIRSTNAME
    from device d, customer c,contact co
    where d.device_type in ('DOS') and d.cust_id = c.cust_id and co.CONTACT_ID = d.device_id;Thanks in advance
    Ravi

    Use outer join:
    select d.device_id,c.ORG_NAME,co.FIRSTNAME
    from device d, customer c,contact co
    where d.device_type in ('DOS') and d.cust_id = c.cust_id and co.CONTACT_ID(+) = d.device_id;SY.

  • Sub-Select SQL query in Oracle BI Answers

    Hi
    What's the proper usage of Sub-Select SQL query in Oracle BI Answers Version Oracle Business Intelligence 10.1.3.2.1?
    I get [SQL_STATE: HY000] [nQSError: 10058] A general error has occured when trying to Sub Select query like:
    itemno = (SELECT MIN(orders.itemno) FROM mydatabase where rownum < 2 order by orders.itemno)

    Maybe the best is to create a new physical and logical object for your sub-select and join this with your current objects.

  • SUB select

    Hi,
    I have 2 reports. The first report contains YYYY, Q, avg(val1).
    2007 Q1 5
    2007 Q2 6
    2007 Q2 7
    Cumul 6
    Besides I want to create a report (gauge) containing the cumul value.
    Therefore it seems that I need to create a SUB select query like this
    select year, avg(avg(val1))
    from (select YYYY, avg(val1) over (partition by YYYY, Q) from table)
    group by YYYY
    Any one an idea how I can fix this in answers??
    Txs for your help

    did you try ∑ option in answers?

  • Needs  help to retrive the last row in a  select query without using rownum

    Hi ,
    i need to retrive the last row from the select sub query without using rownum.
    is there any other way to retrive the last row other than the below query.
    is that the ROWNUM=1 will always retrive the 1 row of the select query ?
    select from*
    *(select ename from employee where dept_id=5 order by desc) where rownum=1;*
    Please advise.
    thanks for your help advance,
    regards,
    Senthur

    957595 wrote:
    Actually my problem is ithat while selecting the parents hiearchy of the child data using
    CONNECT BY PRIOIR query
    I need the immediate parent of my child data.
    For example my connect BY query returns
    AAA --- ROOT
    BBB --PARENT -2
    CCC --PARENT-1
    DDD IS my input child to the connect by query
    Immediate parent of my child data "DDD" ---> CCC(parent -1)
    i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
    I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
    So confusing with using this rownum in my query.
    Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
    you can select the PRIOR values to get the parent details if you want...
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
      2  from emp
      3  connect by mgr = prior empno
      4* start with mgr is null
    SQL> /
         EMPNO ENAME                                 MGR
          7839 KING
          7566   JONES                              7839
          7788     SCOTT                            7566
          7876       ADAMS                          7788
          7902     FORD                             7566
          7369       SMITH                          7902
          7698   BLAKE                              7839
          7499     ALLEN                            7698
          7521     WARD                             7698
          7654     MARTIN                           7698
          7844     TURNER                           7698
          7900     JAMES                            7698
          7782   CLARK                              7839
          7934     MILLER                           7782
    14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data)

  • Prerequisites for multi selection value help

    Hi everyone,
    a couple of blogs and forum entries show multi selection value helps in VC. I, on the other hand, have so far been unable to do this. The only option I get in the first step of the value help wizard is the "single selection" type. Even if I start off with a blank form view and add a text input field I cannot choose anything apart from a single selection value help. Is there something I am completely missing? I stumbled upon a note bringing this into connection with OLAP source systems, but I can't quite see why this should change anything since the source system is not selected until step 2 of the wizard.
    Any idea on this? Thanks a lot,
    Tilman

    Hi Mario,
    thanks for the hints, I got it working now, regardless of whether you use an OLAP source system, variables or the respective input port, though. It seems to suffice to connect the query directly to a form view to get the additional options. My problem was then that I had a form view connected to a nested iview. I should be able to connect it to both a query and the iview, though.
    Thanks for your help,
    Tilman

  • Need help in writing a select query to pull required data from 3 tables.

    Hi,
    I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
    The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
    the role from EmpRoles .
    Sample Script:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1),(2),(3)
    Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
    remaining ID's need to fetch from EmpRoles .
    My Final Output of select query should be like below.
    EmpID Role
    1 Role1
    2 Role2
    3 Role1
    Please help.
    Mohan

    Mohan,
    Can you check if this answers your requirement:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1)
    Insert into #EmpIDs values (2)
    Insert into #EmpIDs values (3)
    Insert into #EmpRoles values (1,'Role1')
    Insert into #EmpRoles values (2,'Role2')
    Insert into #EmpRoles values (2,'Role1')
    Insert into #EmpRoles values (3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    --Method 1
    select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    left join #latestRoles l on e.emplID=l.EmpID
    group by e.EmplID
    --Method 2
    ;with cte
    as
    select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    select emplID,Designation
    from cte
    where cnt=1
    UNION ALL
    select a.EmplID,l.Designation
    from
    (select distinct EmplID from cte where cnt>1) a
    join #Latestroles l on a.EmplID=l.EmpID
    order by emplID
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

Maybe you are looking for