SQL experts please help for a query

I have following table1.
What query can give the result as given below, SQL experts please help on this.
TABLE1
Event DATETIME
in 2/JAN/2010
out 2/JAN/2010
in 13/JAN/2010
out 13/JAN/2010
in 5/JAN/2010
out 5/JAN/2010
RESULT REQUIRED FROM THE SQL QUERY
COL1_IN COL2_OUT
2/JAN/2010 2/JAN/2010
13/JAN/2010 13/JAN/2010
5/JAN/2010 5/JAN/2010

I tried to help, but this puzzles me.
Why is this not returning pre-selected set of rows, why it's doing some merge join cartezian ?
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> select * from table1;
EVENT      DATETIME
in         2/JAN/2010
out        2/JAN/2010
in         13/JAN/2010
out        13/JAN/2010
in         5/JAN/2010
out        5/JAN/2010
6 rows selected.
SQL> explain plan for
  2  with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select  a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
Explained.
SQL> set wrap off
SQL> set linesize 200
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 185132177
| Id  | Operation            | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT     |        |     9 |   288 |     8   (0)| 00:00:01 |
|   1 |  MERGE JOIN CARTESIAN|        |     9 |   288 |     8   (0)| 00:00:01 |
|*  2 |   TABLE ACCESS FULL  | TABLE1 |     3 |    48 |     3   (0)| 00:00:01 |
|   3 |   BUFFER SORT        |        |     3 |    48 |     5   (0)| 00:00:01 |
|*  4 |    TABLE ACCESS FULL | TABLE1 |     3 |    48 |     2   (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
   2 - filter("EVENT"='in')
   4 - filter("EVENT"='out')
Note
   - dynamic sampling used for this statement
21 rows selected.
SQL> with a as
(select datetime from table1 where event='in'),
b as
(select datetime from table1 where event='out')
select  a.datetime COL1_IN ,b.datetime COL2_OUT from a,b ;
COL1_IN         COL2_OUT
2/JAN/2010      2/JAN/2010
2/JAN/2010      13/JAN/2010
2/JAN/2010      5/JAN/2010
13/JAN/2010     2/JAN/2010
13/JAN/2010     13/JAN/2010
13/JAN/2010     5/JAN/2010
5/JAN/2010      2/JAN/2010
5/JAN/2010      13/JAN/2010
5/JAN/2010      5/JAN/2010
9 rows selected.
SQL>

Similar Messages

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • Calling SQL experts to help write a query

    Trying to find some help from some sql experts.
    I was asked to help write a query showing each Dialed_Number, the associated Call_Type, and Script(s) in an ICM configuration.
    All the data I’m looking for seems to be in the following tables:
    Dialed_Number (DialedNumberString, EnterpriseName, DialedNumberID)
    Call_Type (CallTypeID, EnterpriseName)
    Dialed_Number_Map (DialedNumberID, CallTypeID)
    Call_Type_Map (CallTypeID, MasterScriptID)
    Master_Script (MasterScriptID, EnterpriseName)
    Thus far, my query looks like this:
    SELECT     distinct Dialed_Number.DialedNumberString, Dialed_Number.EnterpriseName AS DN_Name, Call_Type.EnterpriseName AS Call_Type_Name,
                          Master_Script.EnterpriseName AS ScriptName
    FROM         Call_Type_Map CROSS JOIN
                          Call_Type CROSS JOIN
                          Dialed_Number CROSS JOIN
                          Dialed_Number_Map CROSS JOIN
                          Master_Script
    However, it’s returning every possible combination (it was 10x worse before adding the word ‘distinct’)
    Ideally, I’d like the results to just show one row for each Dialed_Number (assumes 1:1 ratio of DN to CallType).
    e.g.:
    DN_Name           DialedNumberString      CallType_Name                ScriptName
    Can anyone offer any guidance or suggestion?

    Thanks Geoff,
    I'd put this out on a couple different channels, and while yours is pretty good (I did remove the RoutingClientID from the where clause), I got another version that works just as well, and also includes DNs without CallTypes, and those which may have a CallType, but no script.
    SELECT dn.DialedNumberString, dn.EnterpriseName AS Dialed_Number_Name, ct.EnterpriseName AS Call_Type_Name, ms.EnterpriseName AS Script_Name
    FROM Dialed_Number dn
    LEFT OUTER JOIN Dialed_Number_Map dnm ON dn.DialedNumberID = dnm.DialedNumberID
    LEFT OUTER JOIN Call_Type ct ON dnm.CallTypeID = ct.CallTypeID
    LEFT OUTER JOIN Call_Type_Map ctm ON ct.CallTypeID = ctm.CallTypeID
    LEFT OUTER JOIN Master_Script ms ON ctm.MasterScriptID = ms.MasterScriptID
    I believe the "joins" are supposedly more efficient, too.
    Thanks for your contribution!

  • Please help for my query?

    I have a data table following:
    Field: ID VALUE MONTH
    Data: 111 2 4
    111 6 2
    222 3 3
    222 7 6
    333 5 3
    333 4 5
    333 4 1
    I want to write a query using GROUP BY (ID), SUM(value) AND MAX(Month) that return results following:
    111 8 4
    222 10 6
    333 13 5
    But I don't know to take it. Please help me to resolve this require
    Thanks in advance!
    Edited by: user11807715 on Aug 19, 2009 8:25 PM

    Why wouldn't it just be
    SELECT is, sum(value), max(month)
      FROM your_table
    GROUP BY idJustin

  • SQL Experts, Please help!!

    Hi
    Here is my query:
    select
    --Element Details:
    pet.element_name, pet.element_type_id, pet.reporting_name,
    decode(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
    pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
    --Run Result Details:
    prr.run_result_id,
    NVL(prrv.RESULT_VALUE, 0)"Extra Mileage Details",
    decode(piv.name, 'Pay Value', 'Amount',
    'Number of KMs', 'Total Kilometers Covered',
    'Vehicle Registration No', 'Vehicle Registration No.')"Input Value",
    --Assignment Details:
    paa.assignment_id,
    --Time Period
    ptp.START_DATE, ptp.end_date,
    ptp.period_name "Payroll Period"
    from
    hr.pay_element_types_f pet,
    hr.pay_run_results prr,
    hr.pay_run_result_values prrv,
    hr.pay_input_values_f piv,
    hr.pay_assignment_actions assact,
    hr.per_all_assignments_f paa,
    hr.pay_payroll_actions payroll,
    hr.per_time_periods ptp
    where
    pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
    and prr.run_result_id = prrv.run_result_id
    and piv.input_value_id = prrv.input_value_id
    and assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
    and paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
    and payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
    and ptp.TIME_PERIOD_ID = payroll.time_period_id
    and pet.element_name = 'IVTB Extra Mileage'
    and ptp.end_date between pet.effective_start_date and pet.effective_end_date
    and ptp.end_date between paa.EFFECTIVE_START_DATE and paa.EFFECTIVE_END_DATE
    and ptp.end_date between piv.effective_start_date and piv.effective_end_date
    and paa.payroll_id != 0
    and paa.pay_basis_id != 0
    When I get the results, I get the Pay Value, Kilometers and Vehicle Registration no. in rows. They are my 'input values' having different input ids, however, they have same run result id and thus. I want to display them as separate columns each with the heading 'Pay value' , 'Kilometers' etc. and display my run resulyt value below each heading.
    Is this possible? Can someone plz guide me?
    Thanks in advance.
    Regards,
    Aparna Gupte

    This should be possible with SQL*Plus reporting
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14357/ch6.htm#CHDBEAAB
    think it will be something like this;
    COLUMN Pay_Value NEW_VALUE V_pay_value NOPRINT
    COLUMN Kilometers NEW_VALUE V_Kilometers NOPRINT
    COLUMN Registration NEW_VALUE V_Registration NOPRINT
    TTITLE LEFT 'Heading: ' V_pay_value,V_Kilometers,V_Registration SKIP 2
    BREAK ON piv.name SKIP PAGE
    select
    --Element Details:
    pet.element_name, pet.element_type_id, pet.reporting_name,
    decode(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
    pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
    --Run Result Details:
    prr.run_result_id,
    NVL(prrv.RESULT_VALUE, 0)"Extra Mileage Details",
    decode(piv.name, 'Pay Value', 'Amount',
    'Number of KMs', 'Total Kilometers Covered',
    'Vehicle Registration No', 'Vehicle Registration No.')"Input Value",
    --Assignment Details:
    paa.assignment_id,
    --Time Period
    ptp.START_DATE, ptp.end_date,
    ptp.period_name "Payroll Period"
    from
    hr.pay_element_types_f pet,
    hr.pay_run_results prr,
    hr.pay_run_result_values prrv,
    hr.pay_input_values_f piv,
    hr.pay_assignment_actions assact,
    hr.per_all_assignments_f paa,
    hr.pay_payroll_actions payroll,
    hr.per_time_periods ptp
    where
    pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
    and prr.run_result_id = prrv.run_result_id
    and piv.input_value_id = prrv.input_value_id
    and assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
    and paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
    and payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
    and ptp.TIME_PERIOD_ID = payroll.time_period_id
    and pet.element_name = 'IVTB Extra Mileage'
    and ptp.end_date between pet.effective_start_date and pet.effective_end_date
    and ptp.end_date between paa.EFFECTIVE_START_DATE and paa.EFFECTIVE_END_DATE
    and ptp.end_date between piv.effective_start_date and piv.effective_end_date
    and paa.payroll_id != 0
    order by piv.name,Number of KMs,Vehicle Registration No

  • I bought an iphone 5 from one of my friends and unluckily I had yet lost his contact, I had update this iphone to IOs 7 and now it's be locked at iCloud because there was no password . Actually I dont know what I must do for its. Experts, please help me!

    I bought an iphone 5 from one of my friends and unluckily I had yet lost his contact, I had update this iphone to IOs 7 and now it's be locked at iCloud because there was no password . Actually I dont know what I must do for its. Experts, please help me!

    The friend who sold it to you needed to clear his Apple ID off the phone before he sold it to you. Of course if it wasn't his phone in the first place then he could not do so. He is your friend but you don't know where he is?
    There is nothing that will help you short of getting the password for the Apple ID from your friend. If you cannot obtain that there is no workaround.

  • BDC - table control - experts please help

    Hi experts,
    Please help. I am in need of your help.
    I am working with BDC and I have a table control in one of the screen. Table control has a check box in the first column. While recording how I entered the data is : I select the check box in a row, enter two values in next two columns of that row and then hit enter then the other columns in that row turn from grey to white (initially these columns are greyed out).
    NOw in BDC when I run my session in foreground, I am able to check(select) the check box and enter the values in next two columns and then I have a Enter OKCODE. But when I hit enter it is not able to recognize the row and its unable to turn the greyed out columns in that particular row to white.
    Is there a way to specify in my program that I am hitting enter in one particular row.
    Please help. Let me know if something is not clear. Very urgent . Pleasee respond. Thanks

    Hi Rich,
    Thanks for the replies. I will try that. I got one more doubt. While manually creating the recipes using C201, there is a screen Recipe header. When I record this transaction, I see a different screen for the Recipe header. Fro example the screen numbers are like 4210(manual) and 4211(recording).
    But my problem is there are two fields which are missing in the screen which I am getting while recording C201. These two fields are present on the screen for manual creation. I need to enter those two fields while I record. But how can I do this.
    Please help.

  • Please help for my iphone 4 unlock

    please help for my iphone 4 unlock

    Apple store said my iPhone 4 had an LCD issue and that is why slide to unlock is frozen.  My warranty ran out so it would cost approx. $150 to repair it he said.  Time for a new phone but not sure I want another iPhone now.

  • Hello. Please help. for unknow reasons, I am not getting any of my mail on anything, nothing on my iphone, my outlook or even when I log into icloud online ???   any one else having troble??   please help   I need my mail

    Hello. Please help. for unknow reasons, I am not getting any of my mail on anything, nothing on my iphone, my outlook or even when I log into icloud online>???
    any one else having troble??
    please help
    I need my mail

    Hello, DragonStudios. 
    Thank you for visiting Apple Support Communities.
    Here are a couple troubleshooting resources I would recommend when experiencing issues with iCloud Mail.
    iCloud: Troubleshooting iCloud Mail
    http://support.apple.com/kb/TS4002
    iCloud: Account troubleshooting
    http://support.apple.com/kb/TS3988
    Cheers,
    Jason H.

  • Please help with the query (INSERT RETURNING BULK COLLECT INTO)

    I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
    Here is a full query that use in the C# code
    INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
    BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
    LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
    ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
    VALUES
    (SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
    :REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
    :SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
    :HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
    :CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
    :ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
    :STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
    However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
    Please help me resolve this error or I would appreciate a different solution
    Thank you

    You cannot use (and do not want to in this case) the BULK COLLECT.
    create table for_testing
       the_id      number not null primary key,
       some_data   number
    declare
       l_return_value for_testing.the_id%type;
    begin
      4 
       insert into for_testing
          the_id,
          some_data
       values
          1,
          5
       returning the_id into l_return_value;
       dbms_output.put_line('the return values is ' || l_return_value);
    end;
    20  /
    the return values is 1
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.02
    TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help for a query to add columns

    Hi,
    I need for a query where I should add each TableC value as an additional column.
    Please suggest...
    I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
    Considering Id of TableA.
    Sample data
    TableA     :          
    ID     NAME     TABLENAME     ETYPE
    23     Name1     TABLE NAMEA     Etype A
    TableB     :          
    ID     A_ID     RTYPE     RNAME
    26     23     RTYPEA     RNAMEA
    61     23     RTYPEB     RNAMEB
    TableC     :          
    ID     B_ID     COMPNAME     CONC
    83     26     Comp Name AA     1.5
    46     26     Comp Name BB     2.2
    101     61     Comp Name CC     4.2
    Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
    For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
    Output required: Put each TABLEC value as an additional column
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME     TableC_1_CONC TableC_2_COMPNAME     TableC_2_CONC     
    Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2     so on..
    Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL     
    Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
    Output:
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
    TableC_1_CONCvalue     value     value     value               value

    Hi,
    Welcome to the forum!
    Do you want the data from TableC presented
    (1) in one column, or
    (2) in several columns (a different column of results for each row in the original TableC)?
    (1) Is called String Aggregation and is easier than (2).
    The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
    Ignoring TableA for now, you could get what you want by saying
    SELECT    b.rtype
    ,         STRAGG (   c.compname
                     || ' '
                     || c.conc
                     )  AS c_data
    FROM      TableB  b
    JOIN      TableC  c  ON b.id  = c.b_id
    GROUP BY  b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
    The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
    (a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
    (b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
    The two scripts below contain basic information on pivots.
    This first script is similar to what you would do for case (a):
    --     How to Pivot a Result Set (Display Rows as Columns)
    --     For Oracle 10, and earlier
    --     Actually, this works in any version of Oracle, but the
    --     "SELECT ... PIVOT" feature introduced in Oracle 11
    --     is better.  (See Query 2, below.)
    --     This example uses the scott.emp table.
    --     Given a query that produces three rows for every department,
    --     how can we show the same data in a query that has one row
    --     per department, and three separate columns?
    --     For example, the query below counts the number of employess
    --     in each departent that have one of three given jobs:
    PROMPT     ==========  0. Simple COUNT ... GROUP BY  ==========
    SELECT     deptno
    ,     job
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ,          job;
    Output:
        DEPTNO JOB              CNT
            20 CLERK              2
            20 MANAGER            1
            30 CLERK              1
            30 MANAGER            1
            10 CLERK              1
            10 MANAGER            1
            20 ANALYST            2
    PROMPT     ==========  1. Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno;
    --     Output:
        DEPTNO ANALYST_CNT  CLERK_CNT MANAGER_CNT
            30           0          1           1
            20           2          2           1
            10           0          1           1
    --     Explanation
    (1) Decide what you want the output to look like.
         (E.g. "I want a row for each department,
         and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
    (2) Get a result set where every row identifies which row
         and which column of the output will be affected.
         In the example above, deptno identifies the row, and
         job identifies the column.
         Both deptno and job happened to be in the original table.
         That is not always the case; sometimes you have to
         compute new columns based on the original data.
    (3) Use aggregate functions and CASE (or DECODE) to produce
         the pivoted columns. 
         The CASE statement will pick
         only the rows of raw data that belong in the column.
         If each cell in the output corresponds to (at most)
         one row of input, then you can use MIN or MAX as the
         aggregate function.
         If many rows of input can be reflected in a single cell
         of output, then use SUM, COUNT, AVG, STRAGG, or some other
         aggregate function.
         GROUP BY the column that identifies rows.
    PROMPT     ==========  2. Oracle 11 PIVOT  ==========
    WITH     e     AS
    (     -- Begin sub-query e to SELECT columns for PIVOT
         SELECT     deptno
         ,     job
         FROM     scott.emp
    )     -- End sub-query e to SELECT columns for PIVOT
    SELECT     *
    FROM     e
    PIVOT     (     COUNT (*)
              FOR     job     IN     ( 'ANALYST'     AS analyst
                             , 'CLERK'     AS clerk
                             , 'MANAGER'     AS manager
    NOTES ON ORACLE 11 PIVOT:
    (1) You must use a sub-query to select the raw columns.
    An in-line view (not shown) is an example of a sub-query.
    (2) GROUP BY is implied for all columns not in the PIVOT clause.
    (3) Column aliases are optional. 
    If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
    {code}
    The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
    {code}
    How to Pivot a Table with a Dynamic Number of Columns
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus. 
    (This can be easily adapted to PL/SQL or other tools.)
    PROMPT     ==========  0. Basic Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    PROMPT     ==========  1. Dynamic Pivot  ==========
    --     *****  Start of dynamic_pivot.sql  *****
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    SPOOL     OFF
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    SPOOL     OFF
    --     *****  End of dynamic_pivot.sql  *****
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • I want to submit a concurrent program from pl/sql. Please help me.

    Dear all,
    I want to submit a concurrent program from pl/sql. But I failed. Please help me.
    Detail:
    I create a concurrent program in 'Cash Management, Vision Operations (USA)' responsibility. <strong>And it be submitted success in EBS</strong>.
    Then
    I create a test script in pl/sql. And use 'FND_GLOBAL.APPS_INITIALIZE' to initialize ebs, then use 'FND_REQUEST.SUBMIT_REQUEST' to submit
    the consurrent program, But the procedure aways return <strong>0</strong>.
    I cannot found the reason. Please help me.Thanks.
    <em>Attached informations may describe the problem:
    1.The concurrenct submitted success in EBS.</em>
    request_id = 4750655 (Sorry, I dont know how to add pictures.)
    <em>2.The initialize informations which from SQL</em>.
    SELECT FCR.REQUESTED_BY USER_ID
    ,FCR.RESPONSIBILITY_ID
    ,FCR.RESPONSIBILITY_APPLICATION_ID
    ,FA.APPLICATION_SHORT_NAME
    ,FCP.CONCURRENT_PROGRAM_NAME
    FROM FND_CONCURRENT_REQUESTS FCR
    ,FND_APPLICATION FA
    ,FND_CONCURRENT_PROGRAMS FCP
    WHERE FCR.PROGRAM_APPLICATION_ID = FA.APPLICATION_ID
    AND FCR.CONCURRENT_PROGRAM_ID = FCP.CONCURRENT_PROGRAM_ID
    AND FCR.REQUEST_ID = 4750655;
    Result: user_id = 1318;
    responsibility_id = 50579;
    application_id = 260;
    application_short_name = 'CE';
    program_short_name = 'CALLK009';
    <em>3.The test script code.</em>
    <p>
    -- Created on 2008/10/22 by ERIC
    declare
    -- Local variables here
    Wv_conc_req_id VARCHAR2(10) DEFAULT NULL;
    BEGIN
    FND_GLOBAL.APPS_INITIALIZE(
    1318
    ,50579
    ,260
    Wv_conc_req_id := FND_REQUEST.SUBMIT_REQUEST(
    'CE'
    ,'CALLK009'
    ,NULL
    ,SYSDATE
    ,FALSE
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    DBMS_OUTPUT.PUT_LINE(Wv_conc_req_id);
    COMMIT;
    end;
    <em>4.The concurrent program code.</em>
    create or replace package body CALLTEST is
    PROCEDURE T1(PvO_errbuf OUT VARCHAR2
    ,PvO_retcode OUT VARCHAR2)
    IS
    BEGIN
    FND_FILE.PUT_LINE(fnd_file.log, 'TEST');
    END;
    end CALLTEST;
    </p>

    Can you check from which schema you are executing FND_REQUEST? You can try as follows;
    Connect to your required schema, create a synonym on apps.fnd_request, connect from apps and finally execute grant all on apps.fnd_request to all.
    You can check for relevance from Doc ID: Note:147495.1
    Please do keep in the mind the soultion above should be applied to a test/dev EBS instance first.
    I hope this would be of help.
    Saad

  • Please help with a query

    select * from testme;
    NAME VAL
    A 1
    A 2
    A 3
    B 1
    B 2
    B 3
    C 1
    C 2
    I want to get the maximum of name and the maximum of corresponding name's value.
    ie., the answer should be
    Name VAL
    C     2
    Please help me with the query.
    Thnx

    SQL> create table testme
      2  as
      3  select 'A' name, 1 val from dual union all
      4  select 'A', 2 from dual union all
      5  select 'A', 3 from dual union all
      6  select 'B', 1 from dual union all
      7  select 'B', 2 from dual union all
      8  select 'B', 3 from dual union all
      9  select 'C', 1 from dual union all
    10  select 'C', 2 from dual
    11  /
    Tabel is aangemaakt.
    SQL> select max(name) name
      2       , max(val) keep (dense_rank last order by name) val
      3    from testme
      4  /
    NAME VAL
    C      2Regards,
    Rob.

  • Required help for a query

    Hi All....
    Required help for one more query.
    I have a table with data like this:
    Cust_id Transaction_no
    111 1
    111 2
    111 3
    111 4
    111 5
    111 6
    222 7
    222 8
    333 9
    333 10
    333 11
    333 12
    I wrote the following query :
    select cust_id, ntile(3) over (order by cust_id) "Bucket" from trans_detls
    The output is like this :
    Cust_id Bucket
    111 1
    111 1
    111 1
    111 1
    111 2
    111 2
    222 2
    222 2
    333 3
    333 3
    333 3
    333 3
    The problem is that I dont want the cust_id to overlap in buckets. That is one cust_id should be present in only one bucket.
    Is this possible?
    Thanks in advance.
    Ameya

    Or Something like..
    SQL> select * from test;
            ID         NO
           111          1
           111          2
           111          3
           111          4
           111          5
           111          6
           222          7
           222          8
           333          9
           333         10
           333         11
           333         12
    12 rows selected.
    SQL> select id, ntile(3) over (order by rn) "Bucket"
      2  from(
      3      select id,row_number() over(partition by id order by no) rn
      4      from test);
            ID     Bucket
           111          1
           222          1
           333          1
           111          1
           222          2
           333          2
           111          2
           333          2
           111          3
           333          3
           111          3
           111          3
    12 rows selected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Please help with some query

    hello all!
    please, help me again.
    we have a foreign key discrepancy and my task is to create a view which will show the 3 aspects.
    Let's we have 3 schemas: A - good (which means that i will compare WITH A, source)
    B and C are bad (which mean that I will checking this schemas).
    So, i need to obtain:
    1) FK that DO NOT exist in B&C and do exist in A
    2) FK that DO exist in bad schemas (B&C) but DO NOT exist in good schema (A)
    3) FK's that exist in both (A&B, A&C) schemas on the SAME TABLE, have THE SAME CONSTRAINT_NAME but are on the DIFFERENT columns.
    the first and second I seem to be done through the
    select CONSTRAINT_NAME, TABLE_NAME, STATUS from dba_constraints where owner='PRIV_MD' and CONSTRAINT_TYPE='R' and CONSTRAINT_NAME
    2 NOT IN (select CONSTRAINT_NAME from dba_constraints where owner ='MSA_MD'); (to get the second task we just reversing owners in query and subquery)
    query. but the third one is really pain in my back. i have a query:
    SELECT a.column_name, b.column_name FROM dba_cons_columns a, dba_cons_columns b, dba_constraints c, dba_constraints d
    WHERE c.CONSTRAINT_TYPE='R'
    AND a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
    AND a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    AND b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    AND a.owner = 'PRIV_MD' AND b.owner = 'MSA_MD';
    which runs hours and returns million of rows with the two columns with the same names... but if i'm adding
    AND a.column_name != a.column_name (i'm not sure it's a correct syntax)
    line it returns "no rows selected"
    please, help me obtain it, i'm fighting already the second day..
    (please, don't be angry, i'm just learning and this is my first task on my work...)

    This is basically just a UNION ALL (the constraint columns from both schemas)
    MINUS what exists in both (the INTERSECTion)
    I made it a little more complicated so you could see in which schema the column is used. You could use exactly the same approach for your questions 1 and 2 also.
    SELECT * FROM
    (SELECT a.column_name,c.constraint_name,'salive' schema_containing
    FROM dba_cons_columns a
    INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
    UNION ALL
    select b.column_name,d.constraint_name,'satest'
    FROM dba_cons_columns b
    INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') u
    WHERE NOT EXISTS
    (SELECT *
    FROM
    (SELECT a.column_name,c.constraint_name
    FROM dba_cons_columns a
    INNER JOIN dba_constraints c ON a.CONSTRAINT_NAME = c.CONSTRAINT_NAME
    WHERE a.owner = 'SALIVE' and c.constraint_type = 'R'
    INTERSECT
    select b.column_name,d.constraint_name
    FROM dba_cons_columns b
    INNER JOIN dba_constraints d ON b.CONSTRAINT_NAME = d.CONSTRAINT_NAME
    WHERE d.CONSTRAINT_TYPE='R' AND b.owner = 'SATEST') i
    WHERE u.column_name = i.column_name and u.constraint_name = i.constraint_name)

Maybe you are looking for

  • I can no longer click and drag Safari window to the other desktop.

    I've tried merging all windows and minimizing that single window, then going to the other desktop to open up the window.  That doesn't work--it just opens on the original desktop.  When double-clicking on the Safari icon in the dock, the options for

  • Iphoto problem with software

    ok, new to mac...be patient!! lost my iphoto icon off of my dock. tried to find it and in the process lost my iphoto folder in picures. started a new iphoto, thinking it would restore...not. now i have 2 iphotos when i do a search. one has my photos

  • My bluetooth just started opening on start-up.  how to shut it off

    On start-up, my bluetooth opens up on the taskbar.  It has never done this before.  I dont use any wireless devices.  How do I shut it?  It keeps popping up on start-up.

  • Initial download DNL_CUST_CNDALL failed

    Hi, I am doing initial download of DNL_CUST_CNDALL from ECC6 to CRM7.0. it was shown as as successful in R3AM1 but no data was transferred. When I checked in SLG1 and CND_MAP_LOG_DISPLAY it shows the error message " Value correction USE_NAMESPACE in

  • Regardiing Proejct Resource Management

    Hi, Can any one has any setup or overview document related to Project resource management? I have UG and IG but they are not much friendlier. Please help me out. Regards, Sarvottam.