Need a better query... Join the indictments of two separate queries...

Hi all

I have two separate tables. Initially, I write separate queries to get the number of these tables... Now my requirement is to get the sum of the counts of two queries and I need to write to in a query of monkey...

I wrote something like below... is there any query better than that...
select count  as total from (select distinct site_code,cd_conv_to FROM AA.AAT_440_SVA_DETAIL A , AA.CONV_DETS B , GB.GBT_A02_SITE C WHERE A.PLANT_CODE=B.CD_CONV_FROM AND CD_CONV_TYPE='GSPSPLRG' AND A.SCODE=C.SCODE AND SCODE >= 'C' UNION ALL select distinct T_MANU,cd_conv_to  FROM AA.AAT_447_ISP_Q A , AA.CONV_DETS B , GBT.GBTSITE C WHERE STATUS='VAT' AND A.PCODE=B.CD_CONV AND CD_CONV='GSP' AND A.CD_DIRECT=C.SCODE AND CD_DIRECT >= 'C') q1
Thank you
ASP.

Hello

Try:

SELECT NVL(ilv1.cnt1,0) cnt1, NVL(ilv2.cnt2, 0) cnt2, NVL(ilv1.cnt1, 0) + NVL(ilv2.cnt2,0) total_cnt
  FROM (
  SELECT COUNT(distinct site_code,cd_conv_to) cnt1
     FROM AA.AAT_440_SVA_DETAIL A , AA.CONV_DETS B , GB.GBT_A02_SITE C
  WHERE A.PLANT_CODE=B.CD_CONV_FROM
      AND CD_CONV_TYPE='GSPSPLRG'
      AND A.SCODE=C.SCODE AND SCODE >= 'C' ) ilv1,
  (SELECT COUNT(distinct T_MANU,cd_conv_to) cnt2
      FROM AA.AAT_447_ISP_Q A , AA.CONV_DETS B , GBT.GBTSITE C
   WHERE STATUS='VAT'
    AND A.PCODE=B.CD_CONV
    AND CD_CONV='GSP'
    AND A.CD_DIRECT=C.SCODE AND CD_DIRECT >= 'C') ilv2

Tags: Database

Similar Questions

  • 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.

  • Configure the host and the VM on two separate wireless networks

    Hello community, I was a browser for a long time, but this will be my first post.

    I would like to begin by saying that I have always found the answer I was looking for by browsing these forums and that I browsed discussions thereon and consulted the chapters regarding virtual networks in the manual workstation 7.1, but at this stage were still unable to solve my problem.

    The scenario:

    I'm a small business working in a House (upstairs) / hookah lounge (bottom). We recently had a second internet connection (WORK), Internet home of my family (HOME), to provide our customers with a free wi - fi. I would use the connection of WORK (during our hours of downtime) in a Ubuntu VM for folding and seeding of torrents. I want to put this far on a network traffic will not affect the other.

    The network:

    SE host: Windows 7 Pro 64-bit

    (Host) NIC: Intel PRO/Wireless 3945ABG (Mini PCI)

    VM: Ubuntu 10.04 on VMWare Workstation 7.0.0 build-203739

    NIC (VM): Alfa awus036h (USB)


    The current configuration:

    Network connection is made, the State of replication physical physical network is unchecked.

    The Alfa is connected to the virtual machine and is no longer present on the list of the network adapters in Windows.

    It seems that I have to manually disable the "auto eth 1" interface or the virtual machine using the internet connection in host rather than the network of your choice that the Alfa connects to in VMWorkstation. The speed of the internet with eth auto 1 is connected is quick and consistent, but using it defeats the purpose. Strangely, when I go to network connections, under the "last use" for "eth 1 auto ' it is said 'never '.

    When "eth 1 car" is disconnected, it seems that the virtual machine uses the network wireless connected to the Alfa. But the internet speed is very slow and inconsistent. On downloads, the speed varies considerably; Also, it remains at 0 kb/s for a while before going to 80 KB/s, then works his way down to 0 kb/s again.

    Possible solutions:

    1. it's a driver problem for the Alfa inside the VM environment all this time?

    2 just misunderstood how to set up this kind of virtual network?

    3 is it possible to get the desired configuration by filling the WORK and VMnet0/1/8?

    * Note: Only VMnet1 and VMnet8 appear on the Windows network connections, however isn't VMnet0 bridged one responsible for networking?

    4. upgrade to the current version of the desktop would be useful?

    5. do this problem originally because of some settings on the router?

    * Note: The AP is close enough to provide a signal strength of 85-90%

    Sorry to be so talkative, I just wanted to be as clear as possible because I'm still a beginner to learn more about virtualization.

    Thank you in advance, as always, your help is greatly appreciated.

    First of all, I must say that when I did this last response, I've been on my Mac and I thought the configuration of a host of Windows XP however outside the nomenclature of the names of the host network settings dialog box the rest stands as it is on a host Windows 7 as described below, including a picture as an attachment.

    On a Windows 7 x 64 host with two network adapters, each on a different subnet and VMware Workstation 7.1.3 installed with the editor of virtual computer network configured for VMnet0 and VMnet2 jumpered separately to one of the host of NIC and I have not changed the settings for Windows 7 host NIC-1 and have network/Internet connectivity to the host of this NETWORK adapter as shown in the picture of Google in Internet Explorer on the host computer.  In VMware Workstation 7.1.3 I have a Linux Guest configured to use VMnet2, which is filled in the settings and the Windows 7 host NIC-2 have all with the exception of VMware Bridge Protocol unchecked and have network/Internet connectivity in the guest as indicated by Google in a browser.

    From the perspective of connectivity network between the host and the guest by NIC - 2 on the host computer when all with the exception of VMware Bridge Protocol unchecked there is no connectivity between the two on this subnet because there are no protocol at stake to allow the conversation to take place.

    So theoretically and in practice what I said previously, but didn't were not expressly with a Windows 7 host in mind, nevertheless what I said is true and accurate, as evidenced by world real test/use by what I said and with the image attached herein.

    FWIW Windows 7 has been configured with the default settings and the only changes to the host's network were those made during the installation of VMware Workstation 7.1.3 so with the configuration I discussed with the attached picture, there is no reason why the host and the guest cannot be on different physical networks and each network/Internet connectivity based on the information I have provided and they be isolated from each other by being on separate physical networks.

    That said, even if they can be isolated by being on separate physical networks can still can connectivity between the 2 through VMware shared folders it it turned on and of course & slide and other services so if absolute isolation is necessary to the point where it can be, and the guest still operating system run on a Virtual Machine in the host you would need to disable the Backdoor for VMware Tools cannot provide shared folders on VMware, & glide and other services.  So if you need this isolation level let me know and I will provide additional information to complete it.

  • How can divide you two audio streams to the speakers and the headphones, using two separate takes?

    I am currently using windows 7 and I want to have music that fate of my speakers then I have game sounds threw my helmet. I currently have Hd Realtek Audio Driver.

    Bumping an old topic.

    I also had this works with the Realtek HD Audio Manager.
    There is an option in the settings: "do front and rear output devices play two different audio streams at the same time."
    Check it and you're good.

    It worked!  Thank you!!  I thought that I should buy a 2nd card audio to accomplish this task.  Can't thank you enough.

    And for the person looking for the option, double-click the Realtek speaker icon in the status bar.  When the window appears look on the left side, click on the pinion (Advanced Settings feature) and you'll see the option right there in the middle of the screen.  Check the box, it will reload the audio driver and you will be ready to go!

  • Need to request so that the data dictionary

    Hi all

    I need an application that can show all the details of the tables in my database

    request to see the... : table name, type of name of column data, constraints, default value, etc...

    I found two tables in the database that showa all this information... Here are the 2 quiries:

    Select table_name, column_name | » ('|| DATA_TYPE | (' ('| data_length |')) "column_name from all_tab_columns

    where OWNER = "UBSPROD."

    Select constraint_name, constraint_type, table_name, search_condition_vc, index_name

    From user_constraints where owner = "UBSPROD";

    but when I join them I get a lot of records... I mean I think he's going to cartiantion products

    I used query below:

    Select at.table_name, at.column_name |' ('| at.data_type |') ('|| at.data_length||')) "column_name,
    UC.constraint_name, uc.constraint_type, uc.table_name, uc.search_condition_vc, uc.index_name from all_tab_columns to, uc user_constraints
    where at.owner = 'UBSPROD. '
    and at.table_name = uc.table_name

    Please, help me to display information with all tables of database related...

    Thank you

    The reason you see too many lines is because one table lists columns and a list of constraints and want to join the table name. So if you have a table with 3 constraints and 5 columns, you get 15 lines, which probably makes no sense.

    Have a reflection on what data you actually want to display for each table. There is a many-to-many relationship between columns and constraints (each column can contain zero or more constraints, each constraint can use more than one column), is without doubt better to keep the two separate, for example

    COL1

    COL2

    COL3

    COL4

    COL5

    CONSTRAINT1

    CONSTRAINT2

    CONSTRAINT3

    This would be achieved either with two separate queries, or you can use a UNION ALL operation, as appropriate. If you want to display the columns used in a constraint, you must query the synonym ALL_CONS_COLUMNS.

    Also, make sure you are compatible by using the ALL_ or synonyms USER_ - do not mix the two.

  • Compare the content of two equal nested tables

    I'm working on a black box test where I compare the contents of two structurally equal tables before and after executing a script of some. My two tables, MDQ_OLD and MDQ_NEW, are filled with the data in two separate operations.

    The two tables, I'll compare are nested, as you can see in the CREATE TABLE scripts below.

    I tried to use the less-operator sign, but without success.

    I also tried to select data in a type that is % ROWTYPE to my nested tables, but it does not work as well (see the below script in this post).

    Can you please help me on this problem on how to compare the content of two nested tables?

    Run the scripts below to reproduce the problem and be sure to update this post if more information is required.

    -The scripts below-

    Select * from version of v$.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    PL/SQL Release 11.2.0.4.0 - Production

    CORE Production 11.2.0.4.0

    AMT for Linux: Version 11.2.0.4.0 - Production

    NLSRTL Version 11.2.0.4.0 - Production

    -First of all, I create my types

    CREATE OR REPLACE TYPE FORCE AS OBJECT MDQ_DETAIL (NUMBER OF MDQ_DETAIL_ID, MDQ_DETAIL_DESC VARCHAR2 (100));

    CREATE OR REPLACE TYPE T_MDQ_DETAIL AS TABLE MDQ_DETAIL;

    -Note that this type contains the table T_MDQ_DETAIL type:

    CREATE OR REPLACE TYPE MDQ_PARENT FORCE AS OBJECT (NUMBER MDQ_ID, MDQ_DETAILS T_MDQ_DETAIL);

    - Then I create two equal nested tables

    CREATE THE NESTED TABLE AS MDQ_PR_OLD STORE MDQ_DETAILS MDQ_PARENT MDQ_OLD TABLE.

    CREATE THE NESTED TABLE AS MDQ_PR_NEW STORE MDQ_DETAILS MDQ_PARENT MDQ_NEW TABLE.

    -Insert test data in the nested tables

    Insert into MDQ_OLD (MDQ_ID, MDQ_DETAILS) Values (1, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));

    Insert into MDQ_NEW (MDQ_ID, MDQ_DETAILS) Values (2, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));

    -Try to use the negative operator to compare the contents of the trailer of the nested tables, but it gives this error:

    -ORA-00932: inconsistent data types: expected - got DISPATCH. T_MDQ_DETAIL

    Select * from MDQ_NEW

    less

    Select * from MDQ_OLD;

    -Try to select in a ROWTYPE, but it fails

    declare

    myTypeOld MDQ_OLD % ROWTYPE;

    myTypeNew MDQ_New % ROWTYPE;

    myTypeDiff MDQ_New % ROWTYPE;

    Start

    -Select gives: PLS-00497: do not mix between row and several rows (in BULK) list

    Select * bulk collect into mdq_old myTypeOld;

    Select * bulk collect into mdq_new myTypeNew;

    -Need a 'compare the function of membership card' on the types of multiset except to work, but as far as I

    -I'm not able to bulk collect into myTypeOld or myTypeNew, this won't help out me.

    myTypeDiff: = multiset myTypeOld except myTypeNew.

    end;

    -Cleaning:

    drop table MDQ_OLD;

    drop table MDQ_NEW;

    type of projection MDQ_PARENT;

    type of projection T_MDQ_DETAIL;

    type of projection MDQ_DETAIL;

    > queries you provided intercepts not who.

    You asked how to compare the content of nested tables.

    I knew that you didn't ask for what you actually want, that's why I asked you to specify the comparison more in detail.

    > Do you have a query that grabs this difference as well?

    SELECT o.mdq_id, od.*
    OF mdq_old o, TABLE (o.mdq_details) od
    LESS
    SELECT n.mdq_id, nd.*
    OF mdq_new n, TABLE (n.mdq_details) nd;

    > Also, if possible, do you have a sample of a statement to COLLECT LOOSE, please?

    Actually, you raise an interesting point on using % ROWTYPE, in my view, that should be. This make...

    DECLARE
    TYPE rt_mdq_new () IS RENDERING
    mdq_id NUMBER,
    mdq_details t_mdq_detail);
         
    TYPE tt_mdq_new IS TABLE OF THE rt_mdq_new;
      
    t_mdq_new tt_mdq_new;
    BEGIN
    SELECT mdq_id, mdq_details
    LOOSE COLLECTION t_mdq_new
    OF mdq_new min.;
    END;
    /

    DECLARE
    CURSOR c_mdq_new
    IS
    SELECT mn.*
    OF mdq_new min.;
         
    TYPE tt_mdq_new IS TABLE OF c_mdq_new % ROWTYPE;
      
    t_mdq_new tt_mdq_new;
    BEGIN
    OPEN c_mdq_new.
    Get the c_mdq_new COLLECT in BULK IN t_mdq_new;
    CLOSE C_mdq_new;
    END;
    /

  • How can I implement two TCP/IP servers (on two separate computers) and a TCP/IP client (on the third machine)

    I have an application where I need to send data via TCP/IP from two separate machines to a third machine. The machines are on a local network connected via a network switch. The data are produced independently through data acquisition by two independent machines before are sent to the client on the third machine. Each machine has a network card. Thank you.

    Each server listening on a port separated.  On the client have two loops, each loop tries to open a connection using the IP address of one of the servers on the respective port.  I have this work currently, including the ability to reconnect automatically if a connection is lost.  I could put together a disassembled low example for you if you need.

    It is based on the framework of the STM, you find on the site of NOR and download it.  It includes excellent examples.

  • Parse the string into two double

    Hello everyone, once again

    I'm taking a string of numbers that can be anywhere from - 999999.999999 to + 999999.99999 and separate them into two double rooms. For example, if a user entry - 10000, 10000 - two doubles would be-10000 and-10000. If the user has entered - 10.11111- + 20.00111 he got out - 10.11111 and 20.00111. The VI "Extract the numbers" did perfectly, but I need a way to return the results in two double rooms instead of an array of doubles. I also results to return all the digits after the decimal point for reasons of precision. I use this code within one of my States in a state machine and the driver I use only accepts double rooms.

    The code of "Extract the numbers" VI is attached. Thank you all!

    Hi buickgn,

    When your code works, you should only use IndexArray on outputs. If not, try this one:

  • How to save a calendar I created with the photo and the dates recorded on separate pages?

    How to save a calendar I created in photoshop with the photo and the dates recorded in the form of two separate pages?  When I save in pdf or jpeg, they are automatically save 1 pg with dates and photos on a single page.  This is causing problems when I print.

    Hi there, in which case your printer is not very large, you can also trim down the two versions and print them as separate documents.

    (1) create a guide where you want to split the pages by clicking on the rule (hit control R if they are not displayed) and dragging to the desired location.

    Create the Guide to make it so be precise in the way which divide you your page, and so that no part of the image will be repeated or lost.

    (2) select the Cropping tool and adjust the area of culture at half top of your agenda, using the guide you have just made to align with the right place. Press return to complete the harvest.

    (3) go in file > save as the. Name the file something like calendar_top and select the desired file format. Press "Save".

    (4) once you return to your calendar file, go to the history Panel and select 'Guide to flirting This will bring you to step before you cropped the image.

    (5) repeat the steps as before to the bottom half of the schedule, once more, using the guide to help you make your growing area.

    Then you would just print each of the two pages individually. The images does not appear in a single document, but if you have Acrobat you could combine the files.

    I hope this helps!

  • For a designer of shoes, I need more than photoshop and illustrator? is it better to get the full creative cloud for £58 per month? or would I not need all of them? should I get adobe stock as well?

    For a designer of shoes, I need more than photoshop and illustrator? is it better to get the full creative cloud for £58 per month? or would I not need all of them? should I get adobe stock as well?

    @

    Hi Alice,.

    It's totally up to you who request CC will you use and therefore, you can customize your plans.

    Pricing plans and creative Cloud membership | Adobe Creative Cloud

    You can also join Adobe sales for assistance.

    Kind regards

    Sheena

  • Join the query - confused behavior

    Hello.. I need to make a join on four tables and select one data tables. The query is as below,

    SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND MLR.dslam_tid = NEI.id AND NEI.type = 'OLT' AND MLR.ntwk_type = FIBRE.id AND MLR.master_key = VM.master_key;

    This query works very well. I want to change the query to have an OR condition by combining certain conditions in the WHERE clause as below,

    SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND ((MLR.dslam_tid = NEI.id ET NEI.type = 'OLT') or MLR.ntwk_type = FIBRE.id) AND MLR.master_key = VM.master_key;

    This translates into several duplicates of the correct result lines (about 93 272 rows).
    I suspect this is a unwanted Cartesian product.
    I am limited to use a 'different' because my application performs custom, so 'distinct' query analysis is out of the option.

    I struggle to understand the result of this query. You can help... ! Thanks in advance.

    My database: Oracle Enterprise Edition 10.2.0.2.0

    Published by: vanessa on June 9, 2011 12:49 AM

    Hello

    Can hide you the SELECT DISTINCT in a subquery, like this:

    SELECT  *
    FROM    (
                SELECT DISTINCT  VM.SEGMENT, ...
            );
    

    or in a view?

    If this is not the case, use GROUP BY. The GROUP BY clause contains all the columns in the SELECT clause.

    You could also re - write the query to use EXISTS or IN, instead of a jon.
    For example:

    SELECT      SEGMENT
    ,     CA
    ,     PR
    ,     BP
    ,     TERM_ID
    ,     TL
    FROM     v_mlr_cable     vm
    WHERE     master_key     = 62
    AND     EXISTS (
              SELECT  0
              FROM     v_neicode       NEI
              ,     v_mlr            MLR
              ,      v_fibre_ntwk_type FIBRE
              WHERE     MLR.master_key      = vm.master_key
              AND      (     (     MLR.dslam_tid      = NEI.id
                        AND      NEI.type      = 'OLT'
                        )
                   OR      MLR.ntwk_type      = FIBRE.id
                   )
                )
    ;
    

    Do you think it is easier to read and understand the code formatted, as the query above, or unformatted, as what you posted?
    Who do you think will encourage people to read your question and provide accurate responses?
    Never write, not to mention NPA, not formatted.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) of all the tables and the results desired from these data.
    Explain how you get these results from these data.
    Always tell what version of Oracle you are using.

  • [Help] Join the query from 3 tables

    Hi, I'm new to database. I have a question about joining 3 tables, forgive me for my bad English.

    My paintings look like this

    Table 1: person (id, firstname, lastname)
    Table 2: AssignPersonAddress (id, personid, addressid, type)
    Table 3: address (id, phone, street, etc.)

    I need AssignPersonAddress table, because in my data structure, a person may have more than 1 address and address type must be registered (for example: private, work)


    I want to do a select query to the State any person with his private phone and work phone, like this.
    NOBODY | PRIVATE | WORK



    Right now my query looks like this
    select p.name , a1.tel AS Private, a2.tel AS Work
    from person p, 
    addresse a1 , 
    AssignPersonAddress apd1, 
    AssignPersonAddress  apd2, 
    addresse a2
    
    where p.id  = apd1.person (+)
    and apd1.adresse  = a1.id 
    and apd1.art = 'Private' 
    and p.objectid = apd2.person (+)
    and apd2.adresse  = a2.id 
    and apd2.art = 'Work'
    the problem is that I only get the person who has a private address and the job. But what I want is all anyone no matter if the person has only 1 or 2 address.

    As you can see I put the left outer join in where condition, but I always get the wrong result.


    THX in advance


    Danny

    Published by: raitodn on October 1st, 2009 03:51

    Published by: raitodn on October 1st, 2009 04:12
  • Need of a query to retrieve the data

    Hello

    I have a table named person. It has two fields A_ID and B_ID. The table does not have a primary key
    The data in the table are the following

    A_ID B_ID_ _

    1 5
    1 10
    2 5
    2 10
    4 15
    5 20

    I need to select A_ID and B_ID data so that when you select a given allocation A_ID or B_ID is not for more choices

    For Eg: I select the first pair of 1 and 5. Then 1 and 5 is not in the selection of data from A_ID or B_ID

    The output of the query for the data in the table above should be

    Output

    A_ID B_ID_ _

    1 5
    2 10
    4 15

    Hope you understand the situation.
    Can someone help me to create a query for me

    Thanks in advance

    Published by: user599079 on August 12, 2009 21:40

    This done:

    Nope:

    SQL>  with t as (
     select 1 a_id, 5 b_id from dual union all
     select 1, 10 from dual union all
     select 2, 5 from dual union all
     select 2, 10 from dual union all
     select 4, 15 from dual union all
     select 5, 6 from dual union all
     select 6, 9 from dual
    ),
    union_data  as
    (
        select    a_id    as id
        ,    'A'    as col
        ,    row_number () over (order by a_id, b_id)    as r_num
        from   t
    union all
        select    b_id    as id
        ,    'B'    as col
        ,    row_number () over (order by a_id, b_id)    as r_num
        from    t
    )
    ,    grouped_data    as
    (
        select      id
        ,      min (col) keep (dense_rank first order by r_num)    as first_col
        ,      min (r_num)                                     as first_r_num
        ,      row_number () over ( partition by min (col) keep (dense_rank first order by r_num)
                                  order by        min (r_num)
                         )                    as out_num
        from      union_data
        group by  id
    )
    select      a.id    as a_id
    ,      b.id    as b_id
    from      grouped_data    a
    join      grouped_data    b    on    a.out_num    = b.out_num
    where      a.first_col    = 'A'
    and      b.first_col    = 'B'
    order by  a.out_num
    /
          A_ID       B_ID
    ---------- ----------
             1          5
             2         10
             4         15
    
    3 rows selected.
    

    I expect him back at the last row too much (like my request).
    In addition to change line 5 - 6 5-25 mess up completely:

          A_ID       B_ID
    ---------- ----------
             1          5
             2         10
             4         15
             6         25
    
  • Need advice for optimizing query for the use of function UPPERCASE

    I would like to know if it would make a difference if I use the UPPER function in the WHERE clause compared to use in the SELECT statement. For example:
    SELECT 
        2 AS ORDERID,
        'OFFC' AS RESULTTYPE,
        OFFC_CD AS GROUPCOL,
        SUM(FACE_AMT) AS TOT_FACE_AMT,
        SUM(PROJ_PREM_AMT) AS TOT_PROJ_PREM_AMT,
        COUNT(*) AS TOT_NUM_CASES,
        'YTD' AS RPTTYP
    FROM
    (
        SELECT
            FMI.ACCT_GRP_ID, FMI.GA_CD, FMI.OFFC_CD, FMI.GROUP_REALLOCATION, FMI.STAT_NAME
            ,CASE WHEN FMI.GROUP_REALLOCATION = 'Y' THEN
                SUM(NVL(FMI.FACE_AMT,0)) OVER (PARTITION BY FMI.ACCT_GRP_ID, FMI.AGNT_NAME, FMI.STAT_NAME, FMI.GROUP_REALLOCATION, FMI.LOB_NAME ORDER BY FMI.CA_CS_NUM DESC)
             ELSE
                NVL(FMI.FACE_AMT,0)
             END FACE_AMT
            ,CASE WHEN FMI.GROUP_REALLOCATION = 'Y' THEN
                SUM(NVL(FMI.PROJ_PREM_AMT,0)) OVER (PARTITION BY FMI.ACCT_GRP_ID, FMI.AGNT_NAME, FMI.STAT_NAME, FMI.GROUP_REALLOCATION, FMI.LOB_NAME ORDER BY FMI.CA_CS_NUM DESC) 
             ELSE
                NVL(FMI.PROJ_PREM_AMT,0)
             END PROJ_PREM_AMT    
            ,RANK() OVER (PARTITION BY FMI.ACCT_GRP_ID, FMI.AGNT_NAME, FMI.STAT_NAME, FMI.GROUP_REALLOCATION, FMI.LOB_NAME ORDER BY FMI.CA_CS_NUM) RANKING
        FROM
            IFV_FLD_MGMT_INFO FMI
            JOIN IFT_BAT_PARM BP
                ON  FMI.LST_STAT_DT >= (TO_DATE('01/01/' || TO_CHAR(TO_DATE(BP.PARM_DAT_VAL, 'YYYYMMDD'), 'YYYY'), 'MM/DD/YYYY'))
                    AND BP.BAT_ID = 'CMISFLDMGMT_DT'
        WHERE   FMI.OFFC_CD IN (pOffcCd)
            AND FMI.SHOWINFMR = 'Y'
    )
    WHERE ((GROUP_REALLOCATION = 'Y' AND RANKING = 1) OR (GROUP_REALLOCATION = 'N'))
        AND UPPER(STAT_NAME) = 'PLACED'      
    GROUP BY OFFC_CD
    In the above code, it will make difference if I move function SHIFT of the WHERE clause of a SELECT statement in the inner query as SUPERIOR (CGI. STAT_NAME STAT_NAME)? There will be no long-term performance gain?

    Published by: Kuul13 on July 13, 2009 12:25

    Hello

    Kuul13 wrote:
    ...
    In the analytical functions d0 you want
    PARTITION BY stat_name or
    PARTITION OF SUPERIOR (stat_name)?
    This will really make the difference in the wy data will be partitioned?

    Yes.
    PARTITION BY x means the same as
    PARTITION BY y only if x = y. If stat_name = HIGH (stat_name), then why you never bother to say UPPER (stat_name)?

    If so, then I guess that it may be prudent to use UPPER (STAT_NAME) in the IFV_FLD_MGMT_INFO that is used in the inner query view. In this way, I simply keep the changes in the view and all other queries that use this point of view (as in my example) can directly use STAT_NAME = 'PLACÉ' and not no longer necessary to change the column in the PARTITION clause. What is your suggestion?

    That would certainly make the simplest coding. If the person who uses the display needs the stat_name unconverted, then I think that changing the display is a good idea.

    Also, I can't move where the query condition internal because it will give me different results.

    As far as I know, this would make the subquery produce fewer lines (that's why it would be more efficient). Since you are partitioning by stat_name, lines which produced the subquery would be identical to the lines he now produces and are kept by the Super request. I do not have your tables, so I can't test it really,

  • Need help with the query using the AVG function

    First post here.
    I am a student taking a SQL class and I can't find a query.
    I think I'm close to get it, but I can not quite all the way there.

    Three tables are involved in this problem. Here is a list of the tables and the areas concerned:
    orders table:
      order#
      shipstate
    
    orderitems table:
      order#
      isbn
      quantity         (How many copies of book purchased on that order)
    
    books table:
      isbn
      retail    (retail price of book)
    Problem:
    I want to get an average of "total amount" by shipstate.

    For example, in these tables, there are 8 records of the State of Florida.
    However, there are only 5 unique order # for this State.
    The amount of detail * quantity for these 8 disks (or 5 orders) is $345,10
    Now to get my average $345,10 should be divided by 5. (number of unique commands)
    In the following query it divides this $345,10 8. (number of records)

    How to make this request to divide by the number of unique order # rather than the number of records?
    SELECT shipstate, AVG(quantity * retail)
    FROM orders JOIN orderitems USING (order#)
    JOIN books USING (isbn)
    GROUP BY shipstate
    HAVING SUM(quantity * retail) =ANY
                                  (SELECT SUM(quantity * retail)
                                    FROM books JOIN orderitems USING (isbn)
                                    JOIN orders USING (order#)
                                    GROUP BY shipstate) 
    According to me, once I get this part down, I can understand the rest of the problem.
    The end result, I need, is to find all the individual commands that have a "total amount due" that is greater than the 'average amount due' for this state of clients.

    Any help, suggestions or comments welcome.
    Matt

    Your average take into account the shipstate (8 disks), you can do that for the expected results.
    With some examples of input data it would be easier, but here a try:

    SELECT shipstate, sum(quantity * retail)/count(distinct order#)
    FROM orders JOIN orderitems USING (order#)
    JOIN books USING (isbn)
    GROUP BY shipstate;
    

    Nicolas.

    delete the alias
    Edited by: N. Gasparotto on October 3, 2008 19:28

Maybe you are looking for

  • How do we install the betas of apple.

    I have an ipad that I don't really use if I use it for testing, but how do beta on apple? Help, please

  • Satellite L350 - where to find the latest driver for graphics card?

    I have a Satellite L350.I installed a game (EVE online) and it works as it should; However when I use alt - tab, the game crashes.It is not supposed to do this, and on the other PC it does not crash. I contacted the technical support for the game its

  • iBooks disappear

    I added some books in epub format to my iBook. every time I leave and open iBooks, they disappear. When I add them new iBooks says these books already out you want to replace, and I say Yes... they even I have iBooks data folder in the library/contai

  • Error code: 2000-0146 (laptop hung on "Installation screen Windows updates")

    OK, so I have every time I turn on my computer dell laptop (I have windows vista) it acts like it is to install the updates of windows. He said same facility 3/3 even though the completion bar shows 0%. She does this, is like its about to restart the

  • The Application Data folder disappeared [not visible] _

    It's apparently still operational-[i.e. Dragon user profiles are saved it] but the folder does not appear.Tried a restore of the file to a temporary [in My Documents] location by using the restoration of Seagate. He restored but folder does not show