Help on query Pivot - 11g

I'm working on the database in Oracle 11 g.

I'm trying to join two tables with the following data
tab1
----------
contact_id
full_name
email_id
tel_no
tab2
----------
scr_id
org_id (foreign key to org table)
contact_id (foreign key to contact_id in tab1)
contact_type (will take values 'ID','IDE','DC')
If an organization can have multiple types of contacts as "ID", "IDE", "DC".

I want that they should appear
org_id
id_full_name
id_email_id
id_tel_no
ide_full_name
ide_email_id
ide_tel_no
dc_full_name
dc_email_id
dc_tel_no
I am using code similar to the following (this product full name for 3 values contact types while I needed to produce identification of email and such no columns too)
        SELECT * 
     FROM
     (
          SELECT  org_id,
                        full_name,
               contact_type
                FROM
               tab1,
               tab2
                WHERE
               tab1.contact_id = tab2.contact_id 
     )
     PIVOT
     (
          MAX(full_name)
          FOR contact_type
          IN ('ID','IDE','DC')
     )
Any suggestions?

Hello

Instead of a single aggregate early in the PIVOT clause function, use a list separated by commas of the aggregate functions.
Since you post CREATE TABLE and INSERT the data from the sample statements, I will use scott.emp to illustrate.
Say we want to see the ename, sal and hiredate for the first 3 employees (in alphabetical order) for each job:

WITH     got_r_num     AS
(
     SELECT     ename, job, sal, hiredate
     ,     ROW_NUMBER () OVER ( PARTITION BY  job
                               ORDER BY          ename
                       )         AS r_num
     FROM    scott.emp
)
SELECT       *
FROM       got_r_num
PIVOT       (     MAX (ename)     AS ename
       ,     MAX (sal)     AS sal
       ,     MAX (hiredate)     AS hiredate
       FOR      r_num IN (1, 2, 3)
       )
ORDER BY  job
;

Output:

JOB       1_ENAM 1_SAL 1_HIREDAT 2_ENAM 2_SAL 2_HIREDAT 3_ENAM 3_SAL 3_HIREDAT
--------- ------ ----- --------- ------ ----- --------- ------ ----- ---------
ANALYST   FORD    3000 03-DEC-81 SCOTT   3000 19-APR-87
CLERK     ADAMS   1100 23-MAY-87 JAMES    950 03-DEC-81 MILLER  1300 23-JAN-82
MANAGER   BLAKE   2850 01-MAY-81 CLARK   2450 09-JUN-81 JONES   2975 02-APR-81
PRESIDENT KING    5000 17-NOV-81
SALESMAN  ALLEN   1600 20-FEB-81 MARTIN  1250 28-SEP-81 TURNER  1500 08-SEP-81

I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.

Tags: Database

Similar Questions

  • Need help for query flat_file type clobdata oracle table data.

    Hi Sir,

    I need help to query oracle table flat file data having given clob type.
    Oracle Version:
    
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
    
    
    Source table
    
      CREATE TABLE order_details 
       (     QUEUE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, 
         LINE_SEQNUM NUMBER(10,0) NOT NULL ENABLE, 
         CHAR_DATA CLOB, 
         OPTIMISTIC_LOCK_KEY NUMBER(20,0)
       ) 
    COLUMN FOR CHAR_DATA FLAT_FILE
    EU,6067AT,AT10,000000402004,NexiumGERDManagementProject,Z435,,ZZ29,NIS-GOLD,AT
    EU,6067AT,AT10,000000402038,NIS-OEU-ARI-2007/1,Z450,,ZZ29,NIS-OEU-ARI-2007/1,AT
    EU,6067AT,AT10,000000402039,SymbicortNISinCOPD,Z450,,ZZ29,NIS-REU-DUM-2007/1,AT
    EU,6067AT,AT10,000000402040,D1443L00044SeroquelXRRuby,Z450,,ZZ29,D1443L00044,AT
    EU,6067AT,AT10,000000402041,NIS-GEU-DUM-2008/1,Z450,,ZZ29,NIS-GEU-DUM-2008/1,AT
    EU,6067AT,AT10,000000402042,SonstigeAktivitätenLCM,Z450,,ZZ29,.,AT
    EU,6067AT,AT10,000000402134,D1680L00002Saxagliptin,Z450,,ZZ29,D1680L00002,AT
    EU,6067AT,AT10,000000402199,SeroquelWaveNIS,Z450,,ZZ29,NIS-NEU-DUM-2009/1,AT
    EU,6067AT,AT10,000000402313,SeroquelExtra(D1443L00082),Z450,,ZZ29,D1443L00082,AT
    EU,6067AT,AT10,000000402517,AtlanticD5130L00006(AZD6140),Z450,,ZZ29,D5130L00006,AT
    EU,6067AT,AT10,000000554494,ArimidexSt.Gallen(13+2),Z142,,ZZ09,,AT
    EU,6067AT,AT10,000000554495,ArimidexASCO(5delegates),Z142,,ZZ09,,AT
    EU,6067AT,AT10,000000554496,ArimidexSanAntonio6delegates,Z142,,ZZ09,,AT
    EU,6067AT,AT10,000000554497,ArimidexBreastCancerSummit(13+2),Z130,,ZZ09,,AT
    EU,6067AT,AT10,000000554498,ArimidexEIH(15delegates),Z130,,ZZ09,,AT
    EU,6067AT,AT10,000000554499,ArimidexNIFA(200delegates),Z135,,ZZ09,,AT
    EU,6067AT,AT10,000000554500,ArimidexNIFAworkshops(8x25),Z135,,ZZ09,,AT
    EU,6067AT,AT10,000000554501,ArimidexPraktischeGyn.Fortbildung,Z147,,ZZ09,,AT
    EU,6067AT,AT10,000000554502,ArimidexAGO,Z147,,ZZ09,,AT
    EU,6067AT,AT10,000000554503,ArimidexHämato/OnkologieKongress,Z147,,ZZ09,,AT
    EU,6067AT,AT10,000000554504,ARIMIDEXGYNäKOLOGENKONGRESS,Z147,,ZZ09,,AT
    EU,6067AT,AT10,000000554505,ArimidexChirurgenkongress,Z147,,ZZ09,,AT
    EXPECTED RESULTS:
    AFFIRM_CODE COMPANY_CODE INTERNAL_ORDER_CODE INTERNAL_ORDER_DESC ENIGMA_ACTIVITY             SUB_ACTIVITY_CODE IN_AFF_IND ORDER_TYPE EXTERNAL_ORDER COUNTRY        
    EU          6067AT       AT10                 000000402004       NEXIUMGERDMANAGEMENTPROJECT     Z435           NULL        ZZ29       NIS-GOLD        AT             
    EU          6068AT       AT11                 000000402005       NEXIUMGERDMANAGEMENTPROJECT     Z435           NULL        ZZ29       NIS-GOLD        AT             

    Sorry, my bad. Without database at hand, I'll try 'baby steps' (borrowed from Frank) so you don't confuse it with errors that I might add (happens far too often already, but at least you won't "swallow" as forum members think is one of the main goals of this fighter - help her learn - providing not only the proverbial fish.)
    Search the Forum - your problem is one of its best sellers. Watching {message identifier: = 10694602} ("split string into" was the key word used in research) you can try something as

    select table_row,
           level clob_row,
           regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) the_line
      from (select to_char(queue_seqnum)||':'||to_char(line_seqnum) table_row,
                   char_data
              from order_details
           )
     connect by regexp_substr(char_data,'[^' || chr(13) || chr(10) || ']+',1,level) is not null
            and prior char_data = char_data
            and prior table_row = table_row
            and prior sys_guid() is not null
    

    to get all the s the_lineall CLOB and after that the use of the example even to get your columns of each the_line.

    Concerning

    Etbin

    Edited by: Etbin on 3.2.2013 09:01

    .. .but I m connected to do things according to the instructions, I can't do something.

    Used to happen to me too and I did as told to the but only after explaining any disadvantages, I was aware of in time. The last sentence is usually: "O.K. now be just and Don't come back with that kind of thing when it turns out that this isn't the right thing."
    rp0428 post - something to remember.

  • Help with query Oracle?

    Help with query Oracle?

    Take a look at the query

    Select channel_desc, sum (unit_cost), AVG (Unit_price) of channels C, cost S

    where C.channel_id = S.channel_id

    Group 1,2,3



    the first time the error is "channel_desc not a group by expression"-desc is a varchar type there are 6 channels

    II remove the group by clause and then pops up an error "" not only - group expression to group "".

    All the ideas!

    Select channel_desc, sum (unit_cost), AVG (Unit_price) of channels C, cost S
    where C.channel_id = S.channel_id
    Channel_desc group

  • Need help with query SQL Inline views + Group

    Hello gurus,

    I would really appreciate your time and effort on this application. I have the following data set.

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
    1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19

    Please ignore '-' added for clarity

    I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.

    The query should return the following data set

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
    Here's my query. I'm a little lost.

    Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    de)
    Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
    of the INVOICE
    Sequence_id group check_date, check_number, invoice_number, vendor_number
    ) A, B OF INVOICE
    where A.sequence_id = B.sequence_id


    Thank you
    Nick

    It seems that this is a duplicate thread - correct me if I am wrong in this case->

    Need help with query SQL Inline views + Group

    Kind regards.

    LOULOU.

  • SQL query help in oracle database 11g

    I have test table name these data and column as

    Select t.user_id, t.user_date, t.amount

    t-test

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

    User_id date amount

    10 1/1 / 2011 10

    20/1 2/11/2011

    11 1/3 / 2011 30

    40/2 10/2/2011

    You want to display data in this format...

    User_id date amount here is the logic how to get the amount

    1                  10/1/2011      10                      10

    11 1/2 / 2011 30 10 + 20

    11 1/3 / 2011 60 (10 + 20) + 30

    2                   10/2/2011      40                         40

    SELECT t.user_id, t.user_date, t.amount
    , SUM (t.amount) OVER (PARTITION BY t.user_id
                               ORDER BY t.user_date
                             ) AS the amount
    Of t-test
    ORDER BY t.user_id
    , t.user_date
    ;
  • Need help for query joining views

    Hi all

    I need to run a query that joins a number of tables with multiple instances of the same view.  For example, a view named MY_VALUES, is an array of key / value resembles the following:

    Application_ID Attirbute_Description value

    1 1 000 basic benefit

    1 multiplier 1 0.5

    1 Multiplier_2 1.2

    1 total profit 1,115

    2 1 025 basic benefit

    2 multiplier 1 0,268

    2 Multiplier_2 1.3

    Total profit 2 1.4500

    Say I want a query that selects basic earnings and a multiplier 1 for Application ID 1, as well as, other information from a table called APPLICATION that has a relationship to display pk - fk. I would do the following:

    Select the application. Name, mv1.value, mv2.value

    from dbo. App APPLICATION, dbo. MY_VALUES mv1, dbo. Mv2 MY_VALUES

    where app.id = mv1.application_id and mv1.attribute_description = "Basic benefits"

    and app.id = mv2.application and mv2.attribute_description = id 'multiplier 1'.

    and app.id = 1

    My actual query is similar to this. However, I have many other attributes of the notice I need to select, which requires that the view be attached to several times. After 16 these joins, the request is fine. After 17, however, the query runs always, never return a result within 45 minutes I have let it run.

    Is there a better way to write such a request or an indicator of optimization that would be useful here?

    Any help is greatly appreciated.

    ....

    For this type of application, it is often best to extract multiple lines in a single request on the view and their pivot in the output.

    For example

    Select the application. Name

    , max (CASE when mv.attribute_description = "Core service" then mv.value any other purpose) BaseBenefit

    , max (CASE when mv.attribute_description = 'Multiplier 1' then mv.value any other purpose) Multiplier1

    , max (CASE when mv.attribute_description = 'Multiplier 2' then mv.value any other purpose) Multiplier2

    , max (CASE when mv.attribute_description = 'Multiplier 3' then mv.value end to another null) Multiplier3

    from dbo. App APPLICATION, dbo. MY_VALUES mv

    where app.id = mv1.application_id

    and mv.attribute_description IN ('benefits of home', 'multiplier 'multiplier 'multiplier 3' 2' 1')

    and app.id = 1

    This runs often much better than several joins to the table for the view or the value of the attribute.

  • Help on query: how to produce from columns of ranks?

    Hi all
    I have a table table1 with below the structure and data
    Item     State          Value
    A1      MS          100
    A1      GOA          3
    A1      UP          4
    B2      MS          34
    B2      GOA          55
    B2      PB          3
    B2      DL          4
    B3      MS          99
    B3      TN          1
    I have a requirement to query this table and generate the output below
    Item      MS     GOA     UP     PB     DL     TN
    A1     100      3     4     0     0     0
    B2      34     55     0     3     4     0
    B3      99      0     0     0     0     1
    The problem here is that we can have multiple status codes, so as a result the query should return dynamically the number of columns

    Is it possible to produce above output? Any help will be appreciated.

    Oracle DB Version - Oracle 8i

    Thanks in advance!

    Hello

    This is called a pivot .
    The basic technique is something like:

    SELECT     item
    ,     SUM (CASE WHEN state = 'MS'  THEN value ELSE 0)     AS ms
    ,     SUM (CASE WHEN state = 'GOA' THEN value ELSE 0)     AS goa
    ,     SUM (CASE WHEN state = 'UP'  THEN value ELSE 0)     AS up
    ,     SUM (CASE WHEN state = 'PB'  THEN value ELSE 0)     AS pb
    ,     SUM (CASE WHEN state = 'DL'  THEN value ELSE 0)     AS dl
    ,     SUM (CASE WHEN state = 'TN'  THEN value ELSE 0)     AS tn
    FROM     table_x
    GROUP BY  item;
    

    but this requires you to know indicates how many there are, and what they are, when you write the query.

    Since you have not, you must run a preliminary motion that will generate a select like the one above, or at least SUM expressions for variable columns. This is called dynamic SQL code , and a technique to do this is included below. (The example uses COUNT, but any aggregate, including the SUM function, work).

    Another possibility is the aggregation of the chain, where instead of individual columns for each State, you have a huge column VARCHAR2, formatted to look like separate columns. The avaiable tools to do this in Oracle 8.1 are quite poor, however, so I think you're better with dynamic SQL.

    /*
    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.)
    
    NOTE: Using SQL*Plus file I/O, as in this example, is just
    one of many ways to do dynamic SQL.
    */
    
    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.
    
    */
    
  • Need help with query

    Have the rank as below,

    name of the sum

    100 A1

    -A2 200

    A3 300

    50 A1

    -A2 700

    A3 80

    10 A1

    -A2 90

    30 A3

    Need to query to extract the output like this:

    B1                     B2

    A1 + a3 (Sum) A2 (sum)

    Please help me out of this...

    Hello

    It is difficult to understand what you want... A guess based on many assumptions:

    -B1 and B2 are column headers,
    -"A1 + A3" and "A2" in the 'exit' is simply to indicate that you want the sum of the amounts for the first names.

    -Some of the AI have all their amounts > = 0, others have their amounts<=>
    -You want to make the sum of all positive numbers in the first column and all the negatives in the second column

    SELECT SUM (GREATEST (0, t.amount)) b1

    , B2 SUM (LESS (0, t.amount))

    MYTABLE t

    ;

    (I think there is only a bit of luck it's really what you want, but provide a full test case and the output that you really want and why not, try to explain / explicit rules, then we can give better help)

    Best regards

    Bruno Vroman.

  • Accounting amounts with the help of query description

    Hello!

    I'm stuck with a query.

    I have a request to the list on the General Ledger:

    SELECT SOB.NAME

    ,       GB. PERIOD_NAME

    GCC. SEGMENT2

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) > = 0

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)))

    ELSE 0 END) "DB".

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) < = 0

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) * - 1).

    ELSE 0 END) "CR."

    OF GL_BALANCES GB

    GCC, OB GL_SETS_OF_BOOKS GL_CODE_COMBINATIONS

    WHERE CCG. CODE_COMBINATION_ID = GB. CODE_COMBINATION_ID

    AND GO. ACTUAL_FLAG = "A".

    / * For the objective test to run faster towards the bottom of the query * /.

    - AND GO. PERIOD_NAME = "SZE-14'.

    AND GO. CURRENCY_CODE = OB. CURRENCY_CODE

    AND GO. CATEGORY A NULL VALUE

    AND GO. SET_OF_BOOKS_ID = OB. SET_OF_BOOKS_ID

    SOB.NAME GROUP

    ,       GB. ACTUAL_FLAG

    ,       GB. PERIOD_NAME

    GCC. SEGMENT2

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    NVL (GB. PERIOD_NET_DR, 0)

    NVL (GB. PERIOD_NET_CR, 0)

    SEEN THE SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) <>0

    ORDER BY 1,2,3,4,5,6,7,8,9

    This query works very well and the accountant confirmed that it is to show the right quantities. I want to add the description for the book numbers I've already discovered that the desription is stored in applications. Table FND_FLEX_VALUES_VL. I also discovered that the connection can be established with applications. FND_FLEX_VALUES_VL. FLEX_VALUE and GL_CODE_COMBINATIONS. SEGMENT2 so I changed my query like this:

    SELECT SOB.NAME

    ,       GB. PERIOD_NAME

    GCC. SEGMENT2

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    FVV. DESCRIPTION

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) > = 0

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)))

    ELSE 0 END) "CR."

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) < = 0

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) * - 1).

    ELSE 0 END) "DB".

    OF GL_BALANCES GB

    GCC GL_CODE_COMBINATIONS LEFT JOIN EXTERNAL APPS. FND_FLEX_VALUES_VL FVV ON GCC. = FVV.flex_value, GL_SETS_OF_BOOKS OB SEGMENT2

    WHERE CCG. CODE_COMBINATION_ID = GB. CODE_COMBINATION_ID

    AND GO. ACTUAL_FLAG = "A".

    AND FVV.description is not null

    / * For testing purpose flow down the query faster please comment the following line to the environment of the product * /.

    - AND GO. PERIOD_NAME = "SZE-14'.

    AND GO. CURRENCY_CODE = OB. CURRENCY_CODE

    AND GO. CATEGORY A NULL VALUE

    AND GO. SET_OF_BOOKS_ID = OB. SET_OF_BOOKS_ID

    SOB.NAME GROUP

    ,       GB. ACTUAL_FLAG

    ,       GB. PERIOD_NAME

    GCC. SEGMENT2

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    FVV. DESCRIPTION

    NVL (GB. PERIOD_NET_DR, 0)

    NVL (GB. PERIOD_NET_CR, 0)

    SEEN THE SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) <>0

    ORDER BY 1,2,3,4,5,6,7,8,9

    Which duplicates some lines, if I comment out 'AND FVV.description is not null' this line I see a few lines where the description is null. I think that I am so close to the result, but I'm stuck

    Thanks in advance for your help.

    Zsolt

    Hello!

    I managed to make it work. If anyone else here is the query to work.

    SELECT SOB.NAME 'name '.

    ,       GB. PERIOD_NAME 'period Code.

    GCC. SEGMENT2 'account number '.

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    , T.nev "name of the book.

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) > = 0

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)))

    ELSE 0 END) 'throughput '.

    (CASE WHEN SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0))<=>

    THEN (SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) * - 1).

    ELSE 0 END) 'Crédit'

    OF GL_BALANCES GB

    GCC, OB GL_SETS_OF_BOOKS GL_CODE_COMBINATIONS

    (select flex_value szam, nev description

    from APPS. FND_FLEX_VALUES_VL

    where flex_value_set_id = '1003463'

    ) T

    WHERE CCG. CODE_COMBINATION_ID = GB. CODE_COMBINATION_ID

    AND GO. ACTUAL_FLAG = "A".

    / * For testing purpose speeds up query execution

    - AND GO. PERIOD_NAME = "SZE-14'.

    */

    AND T.szam = Gcc.segment2

    AND GO. CURRENCY_CODE = OB. CURRENCY_CODE

    AND GO. CATEGORY A NULL VALUE

    AND GO. SET_OF_BOOKS_ID = OB. SET_OF_BOOKS_ID

    SOB.NAME GROUP

    ,       GB. ACTUAL_FLAG

    ,       GB. PERIOD_NAME

    GCC. SEGMENT2

    GCC. SEGMENT3

    GCC. SEGMENT4

    GCC. SEGMENT5

    NVL (GB. PERIOD_NET_DR, 0)

    NVL (GB. PERIOD_NET_CR, 0)

    T.Nev

    / * Uncomment to show only values that are not null

    -HAVE SUM (NVL (GB. PERIOD_NET_DR, 0)-NVL (GB. PERIOD_NET_CR, 0)) <> 0

    */

    ORDER BY 1,2,3,4,5,6,7,8,9

  • need help hard query

    Hello

    I'm trying to find out who is the manager who have more number of carried forward under him of emp table

    can you please help me how to find... I searched the forum and I tried some queries but does not work...

    Thank you

    ASP.

    Hello

    You need to display the results of the sample such that people who want to help you can recreate the problem and test their ideas.  Do you think that people can run what you posted?  You must post CREATE TABLE and INSERT statements or equivalent SB.

    Once more, if you use a commonly available table, for example scott.emp, just say.

    Explain how you get these results.  For example, "when I say 'Manager', I mean the employee identified in the mgr column; It does not matter if job = 'MANAGER' or not.  In this issue, I'm only interested in direct subordinates.  For example, the KING (empno = 7839) is Manager, directly or indirectly, the other 13 lines in the table, but only 3 of these lines have mgr = 7839.  There are 5 lines having mgr = 7698 (for BLAKE), so I want BLAKE rather than KING. »

    Here's a way to do it:

    WITH got_rnk AS

    (

    SELECT m.empno, m.ename, m.job - or other columns of your choice

    EARL of (e.mgr) AS reportee_count

    , EVALUATE () OVER (ORDER OF COUNT (*) / / DESC) AS rnk

    FROM scott.emp m

    LEFT OUTER JOIN scott.emp e ON e.mgr = m.empno

    GROUP OF m.empno, m.ename, m.job

    )

    SELECT reportee_count, empno, ename

    OF got_rnk

    WHERE rnk = 1

    ;

    Exit from scott.emp (in the case that is different from what you have posted);

    EMPNO, ENAME, JOB REPORTEE_COUNT

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

    7698 BLAKE MANAGER 5

    If there be a tie for the line with the majority of direct reports, the above query will display all the contenders.

  • Help the query group

    HII Guru

    Please help me.

    I have question

    Select

    HP.party_name as a customer,

    RCT.trx_number like Bill,

    RCT.trx_date,

    rctl.attribute3 as Faktur_Pajak,

    rctl.attribute4 as TIN,

    rctl.line_number not,.

    rctl. Description,

    GCC. Segment1 |'. ' | GCC. Segment2 |'. ' | GCC.segment3 |'. ' | GCC.segment4 |'. ' | GCC.segment5 |'. ' | GCC.segment6 as COA,

    rctl.extended_amount as long as dpp,.

    rctl.extended_amount * avt.tax_rate / 100 / rctl.extended_amount * 100 as tax_rate,.

    rctl.extended_amount * avt.tax_rate / 100 as NPP

    Of

    ra_customer_trx_lines_all rctl,

    ra_customer_trx_all rct,

    hz_cust_accounts AOB,

    hz_parties hp,

    ar_vat_tax_all_b avt,

    gl_code_combinations gcc,

    ar_memo_lines_all_b amb

    where 1 = 1

    and rct.org_id = "122"

    and rct.trx_number = 'ExpressMay14.13143. '

    and rctl.memo_line_id = amb.memo_line_id

    and amb.gl_id_rev = gcc.code_combination_id

    and hca.party_id = hp.party_id

    and rct.customer_trx_id = rctl.customer_trx_id

    and rct.sold_to_customer_id = hca.cust_account_id

    and avt.vat_tax_id = rctl.vat_tax_id

    and rctl.description is not null

    and rct.trx_date BETWEEN TO_DATE('05/01/2014','MM/DD/YYYY') AND TO_DATE('05/07/2014','MM/DD/YYYY')

    order of trx_date

    and the result is

    CUSTOMERINVOICETRX_DATEFAKTUR_PAJAKTINNO.DESCRIPTIONCOAGP3TAX_RATENPP
    EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0001BKS-Express21.W10.544300.0000.000.0002 664 750126 648
    EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0002Stamp duty21.000.807220.0000.000.0006 00000

    actually I want to display as

    CUSTOMERINVOICETRX_DATEFAKTUR_PAJAKTINNO.DESCRIPTIONCOAGP3TAX_RATENPPTotal
    EVAGENITA, UDExpressMay14.131432 May 14040.001 - 14.8163714907.358.521.8 - 311,0001BKS-Express21.W10.544300.0000.000.0002 664 750126 648
    2Stamp duty21.000.807220.0000.000.0006 000002 697 398
    Consider the 
    
    with t
    as
    (
    ...
    )
    
    As your actual query. You can do this.
    
    SQL> with t
      2  as
      3  (
      4  select 'EVAGENITA, UD' customer
      5       , 'ExpressMay14.13143' invoice
      6       , to_date('2-May-14','dd-mon-rr') trx_date
      7       , '040.001-14.81637149' faktur_pajak
      8       , '07.358.521.8-311.000' npwp
      9       , 1 no
     10       , 'BKS-Express' description
     11       , '21.W10.544300.0000.000.000' coa
     12       , 2664750 dpp
     13       , 1 tax_rate
     14       , 26648 pnn
     15    from dual
     16  union all
     17  select 'EVAGENITA, UD' customer
     18       , 'ExpressMay14.13143' invoice
     19       , to_date('2-May-14','dd-mon-rr') trx_date
     20       , '040.001-14.81637149' faktur_pajak
     21       , '07.358.521.8-311.000' npwp
     22       , 2 no
     23       , 'Stamp Duty' description
     24       , '21.000.807220.0000.000.000' coa
     25       , 6000 dpp
     26       , 0 tax_rate
     27       , 0 pnn
     28    from dual
     29  )
     30  select decode(rno, 1, customer) customer
     31       , decode(rno, 1, invoice) invoice
     32       , decode(rno, 1, trx_date) trx_date
     33       , decode(rno, 1, faktur_pajak) faktur_pajak
     34       , decode(rno, 1, npwp) npwp
     35       , no
     36       , description
     37       , coa
     38       , dpp
     39       , tax_rate
     40       , pnn
     41       , case when
     42               rno = cnt then
     43                 sum
     44                 (
     45                    dpp+pnn
     46                 )
     47                 over
     48                 (
     49                   partition
     50                          by customer
     51                           , invoice
     52                           , trx_date
     53                           , faktur_pajak
     54                           , npwp
     55                       order
     56                          by no
     57                 )
     58         end total
     59    from (
     60            select t.*
     61                 , row_number() over
     62                                (
     63                                   partition
     64                                          by customer
     65                                           , invoice
     66                                           , trx_date
     67                                           , faktur_pajak
     68                                           , npwp
     69                                       order
     70                                          by no
     71                                ) rno
     72                 , count(*)     over
     73                                (
     74                                   partition
     75                                          by customer
     76                                           , invoice
     77                                           , trx_date
     78                                           , faktur_pajak
     79                                           , npwp
     80                                ) cnt
     81              from t
     82          );
    
    CUSTOMER      INVOICE            TRX_DATE  FAKTUR_PAJAK        NPWP                         NO DESCRIPTION COA                               DPP   TAX_RATE        PNN      TOTAL
    ------------- ------------------ --------- ------------------- -------------------- ---------- ----------- -------------------------- ---------- ---------- ---------- ----------
    EVAGENITA, UD ExpressMay14.13143 02-MAY-14 040.001-14.81637149 07.358.521.8-311.000          1 BKS-Express 21.W10.544300.0000.000.000    2664750          1      26648
                                                                                                 2 Stamp Duty  21.000.807220.0000.000.000       6000          0          0    2697398
    
    SQL>
    
  • Help on query writing

    Hi all

    I tried my best to write the query level, but could not perform. Need help on written request, details I explained below:

    Create the table as follows:

    CREATE TABLE STS_DESC)

    STS_CODE VARCHAR2 (15).

    HEADER_ID NUMBER (15.0).

    NUMBER (15.0) CLOSED.

    TRANSACTION_ID NUMBER (15.0));

    Insert data below in the table:

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 100074, 23977, 308);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 100074, 23977, 969);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100074, null, 114).

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100074, null, 228);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100074, null, 292);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 100076, 23966, 329);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100076, null, 118);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100084, null, 134);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 100084, null, 136);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 100777, 24001, 1701);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 100777, 24001, 1819);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 109920, 24102, 165223);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 109920, 24102, 165225);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('ABC TYPE', 109928, 24103, 165261);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('TYPE ABC', 109928, null, 165259);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ("BE CORP", 100796, null, 1739);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ("BEING FISCAL" 100796, null, 7048);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('OPS AMT', 100074, null, 169);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('OPS AMT', 100076, 23966, 171);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('PQR TYPE', 100074, 23977, 942);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('PQR TYPE', 100074, 23977, 1136).

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('PQR TYPE', 100074, null, 141).

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('PQR TYPE', 100076, 23966, 143);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('PQR TYPE' 100777, null, 2218);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ("TYPE XYZ", 100074, null, 155);

    Insert into STS_DESC (STS_CODE, HEADER_ID, CLOSED, TRANSACTION_ID) values ('XYZ TYPE', 100076, 23966, 157);

    Scenarios

    (1) a header_id may have a sts_code or several sts_code

    Example: 1) = 109928 header_id, there a sts_code

    (2) header_id = 100074, there several sts_code

    (2) Perticular header_id for sts_code considered closed if it has at least a non-null value for the column 'Closed' with the combination of sts_code and header_id

    Example: 1) header_id = 100076 is considered to be closed. Because the combination of sts_code and header_id has at least a non null value for the column 'closed '.

    (2) = 109928 header_id is closed.

    I need to display the header_id which is not closed. Expected result is the following:

    Header_id

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

    100074

    100777

    100796

    100084

    I wrote under query, but it does not give the expected results. Need help on this.

    Select fb1.header_id from STS_DESC Fb1

    Where

    (

    (Not Exists

    (

    Select 1 from STS_DESC Fb2

    Where Fb1.header_id = Fb2.header_id

    And Fb1.sts_code <>Fb2.sts_code

    And Fb2.closed is not Null

    ) And Fb1.closed is not Null

    )

    OR

    (Not Exists)

    Select 1 from STS_DESC Fb2

    Where Fb1.header_id = Fb2.header_id

    And Fb1.sts_code = Fb2.sts_code

    and fb2.closed is not null

    ) )

    )

    Thank you

    SK

    Select

    FB1.header_id

    Of the Fb1 STS_DESC

    Group

    FB1.header_id, sts_code

    seen ((closed) count = 0)

  • I need help for query AVG

    I need help with a simple query in an ORACLE database. I tried a lot of things that I found on the internet, but none of them worked for me.

    The following query retrieves four lines:

    SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3

    Of asw_lab

    WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM < 5

    ORDER BY sampled_date DESC;

    I would like to calculate a moving average of the last four values with the date of the sample of the last line.

    For example, I have this result for the query above:

    Value1 value2 value3

    01/04/14-16:00 1 0

    01/04/14 15:00 2 0

    01/04/14 14:00 3 0

    01/04/14 13:00 4 0

    I want to extract the below my average/query calculation result:

    Value1 value2 value3

    01/04/14-16:00 2.5 0

    Can you help me create a request to that effect?

    Thank you

    Maybe it's

    Select max (VALUE1) VALUE1, VALUE2 avg (VALUE2), avg (VALUE3) value3

    Of

    (

    SELECT sampled_date AS VALUE1, VALUE2 AS result, 0 as value3

    Of asw_lab

    WHERE template_result = 'A' AND analysis = 'B' AND ROWNUM<>

    )

  • Need help with query Cumulative difference

    Hi all

    I need help with a query and my requirement is as below

    {code}

    ROWNOORDERSVALUE

    110900
    211700
    312500
    413400

    {/ code}

    I have need to query which will display the cumulative difference for example I value tell 10000 numbers opening

    now I need for each of the lines of cumulative difference

    {code}

    ROWNO ORDERS DIFF

    1 10 10000 - 900 = 9100

    2 11 9100 - 700 = 8400

    3 12 8400 - 500 = 7900

    4 13 7900 - 400 = 7500

    {/ code}

    WITH commands LIKE (10 SELECT order_id, 900 double UNION ALL val
    11. SELECT, 700 FROM dual UNION ALL
    SELECT 12, 500 FROM dual UNION ALL
    Select 13, 400 double)

    SELECT row_number() over (ORDER BY order_id ASC) AS rowno
    order_id
    sum (val) 10000 - OVER (ORDER BY order_id ASC) AS diff
    orders

    /

    HTH

  • Helps the query in the effects control.

    Hello everyone, I hope that someone can help you.

    I have a little trouble trying to move images around the screen in my sequence to create an animation of a cursor moving to another location. The problem is when I put a marker in the query in the effect control to it's own journey sometimes going upward or down or left or right. I see that there are lines that are the focus of the image, as well as those of the tool pen in Photoshop and I think that that is what is causing the image of the cursor moving on its own. The two same lines by an image to make a smooth arch of movement these lines of travel to smooth the movement rather than a simple at the following location.

    I was wandering because this is the case whenever I put a new marker in the motion effects controls if there is something that is originally what I can disable. I can move these lines from the central point, but that does not make the smoother actions in my sequence.

    Any help is really appreciated.

    You set keyframes on linear:

    Adobe Premiere Pro help. Control to make changes using keyframe interpolation

Maybe you are looking for

  • I can't get rid of an empty box with the header of Mozilla Firefox.

    This rectangular box just won't go away. It lies in the middle of the screen and obscures the rest of the page. I tried to restart unsuccessfully.

  • password disappeared during migration

    I installed Mozilla on the new computer. Created a new profile. Copied all the files from my old computer to the new folder profile. After the launch of Mozilla a few splash screen displays who told me sth. on the conversion of profile. After complet

  • ALT codes don't appears.

    I bought a new laptop with windows 7 a few months ago and found immediately that with firefox, alt codes/symbols are not displayed correctly. They work properly on other browsers, but firefox specifically will not make the characters, showing me spac

  • G62 b15sv: hp g62 b15sv SATA and SSD

    Hi, this is my first post ever on a forum and I have to say, sorry for the English... my HARD drive started to fail a few days ago and I prefer to replace it with an SSD, here's my question 2 I force find what SATA is using my laptop (sata2, sata2, s

  • Sync music from CD using Windows Media player for Ipod

    Original title: Media Player for IPOD Is there a simple way, or any way to load the CD through Windows Media Player on my IPOD?