Separate operation using GROUP BY

I was researching on the extraction of duplicates in a table.

create table x
(empid number,
empname varchar2(50)
);

insert into x values (1,'John');
insert into x values (2,'Reynolds');
insert into x values (3,'Harrison');
insert into x values (1,'Kate');
insert into x values (2,'Hans');


SQL> select * from x;

     EMPID EMPNAME
---------- ------------------------------
         1 John
         2 Reynolds
         3 Harrison
         1 Kate
         2 Hans
         

SQL> select empid from x group by empid;          ------ Query 1

     EMPID
----------
         1
         2
         3         
         
SQL> select min(empid) from x group by empid;      ------ Query 2

MIN(EMPID)
----------
         1
         2
         3


SQL> select * from x where empid not in
  2  (select min(empid) from x group by empid);   -------- Query 3    

no rows selected
I understand how the query 1 and query 2 retrieves distinct values. Query 3 impossible to extract values duplicate because it is equivalent to
SQL> select * from x where empid not in
  2  (select distinct(empid) from x);

no rows selected
Am I wrong?

From different threads OTN, I gathered that a query using ROWID should be used to extract duplicate rows.
Something like
select * from x where rowid not in
(select min(rowid) from x group by empid);   ------------- Query 4
How to work with this query (query 4) and 3 of the application does not work?

Hello

Y.Ramlet wrote:
I was researching on the extraction of duplicates in a table.

create table x
(empid number,
empname varchar2(50)
);

insert into x values (1,'John');
insert into x values (2,'Reynolds');
insert into x values (3,'Harrison');
insert into x values (1,'Kate');
insert into x values (2,'Hans');

SQL> select * from x;

EMPID EMPNAME
---------- ------------------------------
1 John
2 Reynolds
3 Harrison
1 Kate
2 Hans

SQL> select empid from x group by empid;          ------ Query 1

EMPID
----------
1
2
3         

SQL> select min(empid) from x group by empid;      ------ Query 2

MIN(EMPID)
----------
1
2
3

SQL> select * from x where empid not in
2  (select min(empid) from x group by empid);   -------- Query 3    

no rows selected

I understand how the query 1 and query 2 retrieves distinct values. Query 3 impossible to extract values duplicate because it is equivalent to

SQL> select * from x where empid not in
2  (select distinct(empid) from x);

no rows selected

Am I wrong?

Yes, you're right. 3 and 4 of the query request to get the same results (or lack of results) in different ways.

From different threads OTN, I gathered that a query using ROWID should be used to extract duplicate rows.
Something like

select * from x where rowid not in
(select min(rowid) from x group by empid);   ------------- Query 4

How to work with this query (query 4) and 3 of the application does not work?

They both work. they get different results because they are different things.
ROWID is unique; EmpID is not. When you "GROUP BY empid", no matter what group with more than one Member will have ROWID that is not equal to MIN (ROWID) for this group.

Tags: Database

Similar Questions

  • WITH THE HELP OF SEPARATE OR ONE GROUP WHEN IN PRIMARY KEY CLAUSE

    I WANT A WAY TO EFFECTIVELY PERFORM AGGREGATE FUNCTIONS ON A PARTNER OF THE PARENT TABLE CHILD TABLE AND RETURN ALL THE COLUMNS IN THE PARENT TABLE AND CALCULATED FROM THE CHILD TABLE COLUMNS.

    THE PROBLEM IS THAT WHEN I USE GROUP BY ON ALL FIELDS IN THE PARENT, INCLUDING THE PARENT TABLE TABLE, I THINK THAT ORACLE TESTS ALL THE COLUMNS IN THE GROUP BY CLAUSE WHEN IT SHOULD GO HAS THE PRIMARY KEY MAKES ALL IMPLICITLY SEPARATE LINES.

    I CREATED TWO TEST TABLES AND RRAN SOME QUERIES TO TEST AT THE SAME TIME.

    HERE ARE THE TABLES:

    CREATE TABLE A_PARENT_TABLES
    (ACTIVATE THE NUMBER PT_PARENT_TABLE_ID (20.0) NOT NULL,)
    PT_GRP_FEILD1 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD2 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD3 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD4 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD5 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD6 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD7 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD8 NUMBER (20.0) NOT NULL ACTIVATE.
    PT_GRP_FEILD9 NUMBER (20.0) NOT NULL ACTIVATE.
    ENABLE CONSTRAINT A_PARENT_TABLES_PK PRIMARY KEY (PT_PARENT_TABLE_ID)
    );

    CREATE TABLE A_CHILD_TABLES
    (ACTIVATE THE NUMBER CT_CHILD_TABLE_ID (20.0) NOT NULL,)
    CT_PARENT_TABLE NUMBER (20.0) NOT NULL ACTIVATE.
    CT_VALUE_TO_SUM NUMBER (20.0) NOT NULL ACTIVATE.
    ACTIVATE THE CONSTRAINT A_CHILD_TABLES_PK PRIMARY KEY (CT_CHILD_TABLE_ID)
    CONSTRAINT CT_PARENT_TABLE_FK FOREIGN KEY (CT_PARENT_TABLE)
    REFERENCES A_PARENT_TABLES (PT_PARENT_TABLE_ID) ON DELETE CASCADE ALLOW
    );


    I HAVE INSERTED THEN 20,000 RECORDS IN THE A_PARENT_TABLES TABLE AND 60,000 IN A_CHILD_TABLES (3 FOR EACH PARENT)
    I THEN RAN THE FOLLOWING QUERY:


    -ALL FIELDS GROUGPED
    SELECT
    PT_PARENT_TABLE_ID,
    PT_GRP_FEILD1,
    PT_GRP_FEILD2,
    PT_GRP_FEILD3,
    PT_GRP_FEILD4,
    PT_GRP_FEILD5,
    PT_GRP_FEILD6,
    PT_GRP_FEILD7,
    PT_GRP_FEILD8,
    PT_GRP_FEILD9,
    SUM (CT_VALUE_TO_SUM) AS SUMED_VALUES
    Of
    A_PARENT_TABLES,
    A_CHILD_TABLES
    WHERE
    PT_PARENT_TABLE_ID = CT_PARENT_TABLE;

    GROUP BY
    PT_PARENT_TABLE_ID,
    PT_GRP_FEILD1,
    PT_GRP_FEILD2,
    PT_GRP_FEILD3,
    PT_GRP_FEILD4,
    PT_GRP_FEILD5,
    PT_GRP_FEILD6,
    PT_GRP_FEILD7,
    PT_GRP_FEILD8,
    PT_GRP_FEILD9;


    At TOOK 2.42 seconds set IN ŒUVRE



    -ONLY GROUPED FIELDS
    SELECT
    PT_PARENT_TABLE_ID,
    SUM (CT_VALUE_TO_SUM) AS SUMED_VALUES
    Of
    A_PARENT_TABLES,
    A_CHILD_TABLES
    WHERE
    PT_PARENT_TABLE_ID = CT_PARENT_TABLE
    GROUP BY
    PT_PARENT_TABLE_ID;


    At TOOK 0.71 seconds set IN ŒUVRE


    WHY DOESN'T THE FIRST QUERY ARE REALIZING THAT HAVING PT_PARENT_TABLE_ID (PRIMARY KEY) IN THE GROUP BY CLAUSE MEANS THAT NO OTHER COLUMNS SHOULD BE CHECKED?

    HOW CAN I ACHIEVE THE EQUVILENT OF THE FIRST QUERY IN A WAY MORE EFFECTIVE?

    Hello

    As you can see on the plain explain command
    This full table scan done query1 on A_PARENT_TABLES
    query2 done index range scan on A_PARENT_TABLES

    This is one of the reasons why query2 runs faster than the application 1.

    Why complete analysis of table to query1?
    Its because you want in query1 to display other fields present in A_PARENT_TABLES and is not present in the primary index of this table, that is why he must go to the table for the data.

    Hope this helps.
    Concerning
    Anurag Tibrewal.

  • Mail has stopped allowing me to use Group addresses

    I'm under El Cap 10.11.6.

    Mail left allowing me to use Group addresses. I tried manually, type the group name in the address bar, add the group by using the + function and click and drag.

    When I use the + function, the group is displayed but cannot be selected.

    What is the solution?

    Plot thickens: when I manually add recipients to the BCC line, the email will send but is never received by anyone on any address line.

    I sent from iPad and a Mac, same result. question about iCloud?

  • After using groups of tabs earlier today, now whenever I close FF with more than 1 open tab, FF don't ask me to confirm before closing

    After using groups of tabs earlier today, now whenever I close FF with more than 1 open tab, FF don't ask me to confirm prior to closing. FF always asked me to confirm in the past and no settings have been changed before you try tab groups. Then when I open FF it again all the tabs I had open are still there. I tried refreshing FF and erase history, but that did not work. It's almost as if FF think windows and tabs I have open are a group of tabs, and he won't let me get rid of this group. How to stop groups of tabs now that I have them? Or is there something else? None of this was going on until this morning, I played with tab groups. I was curious what it was - it's going to make me kill one of these days lol.

    Note that using "show my windows and tabs from last time" as the start setting will also prevent Firefox to display an alert when you close the window.

  • Cannot map drives using Group Policy objects in Vista

    Hi all

    We strive map drives using Group Policy on our image of Vista. (In the past, we have used kixtart, but try to avoid writing scripts).

    The installer under User Preferences/Configuration/Windows Settings/Player cards of the GPO. Because the GPO is attached to the ORGANIZATIONAL unit that contains the Vista PC, we both loop processing market.

    Extensions side customer GP are installed on the workstation.

    The results are inconsistent - at best, if we use 'Create', 'Update', or 'Replace' as the action of the drive mapping.

    Sometimes, card readers, sometimes they are not. They just recently. Nothing is mentioned in one of the newspapers.

    All the world did this with success?

    Hi OxG,

    Thank you for visiting the Microsoft answers community site. The question you have posted is linked to the Group Policy object and would be better suited to the TechNet Discussion groups. Please visit the link below to find a community that will provide the support you want.

    http://social.technet.Microsoft.com/forums/en/category/windowsvistaitpro

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Uninstall IE and set another web browser such as Chrome and FireFox by default by using Group Policy

    Hello

    Please someone can instruct me on how to uninstall IE and set another web browser such as Chrome and FireFox by default by using Group Policy. Your help would be much appreciated.

    Kind regards

    RocknRollTim

    Hi Tim,.

     

    Thanks for posting your query in Microsoft Community.

    I wish to inform you that, group policy can only be changed if you are using Windows 7 Professional on your computer.

     
    Referring to your other posts, I see that your computers are on a domain network, we have a specific forum for the computers in the domain and they are experts in this field of investigation and would be in a better position to address the concerns. So refer to the link below and post your query on the TechNet Forums.
     
    Hope this information helps, just answer for all the help on Windows.
  • Activate the user audit logs and hide the other audit logs account system on computers in a domain by using Group Policy

    Hello

    Please could someone advise me on how to activate the user audit logs and hide the other audit logs account system on computers in a domain by using Group Policy. Your help would be much appreciated.

    Kind regards

    RocknRollTim

    Hello

    Please contact Microsoft Community.

    We have a specific forum for the computers in the domain and they are experts in this field of investigation and would be in a better position to address the concerns. So refer to the link below and post your query on the TechNet Forums.

    https://social.technet.Microsoft.com/forums/en-us/home

    I hope this helps. If you have any questions on Windows, please answer. We will be happy to help you.

  • How to limit the number of printers can be installed on this computer by using Group Policy?

    How to limit the number of printers can be installed on this computer by using Group Policy?

    Hello

    Thanks for asking! If I understand correctly, you should limit the printers installed on the computer by using Group Policy. I suggest you follow the troubleshooting steps to check if this may help.

    The question you have posted is related to Technet and would be better suited to the Technet community. Please visit the link below to find a community that will provide the best support.
    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

  • Problem with subtotal and grand total using GROUP BY ROLLUP.

    Hi all

    I have a question about the SQL. I need to have the subtotal for each group and total for the entire inside of my request. I've had using GROUP BY ROLLUP to have total subtotal and big inside of my request.

    However, it not successful I want. In addition, my data must be presented in the medium hierarchy. So, I also use CONNECT BY permission inside my request.

    The query returned the results but not as my expected.

    Below is all about the tools used, description of flows, issues, query used, sample data, out of the request as well as the expected results: -.

    Tools used: -.

    • Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Description of the flow: -.

    Lily is an AM of agency which is the highest level of management (LEVEL 1). Kevin is the direct agent under the lilies and the sum of productivity(upstream)

    for each of them must be sum up as the Subtotal. Sarah and Tom is the Unit Manager (UM) (LEVEL 2) who reports to Lily. They have the direct agents (Agent) under each of them which are may, John, Sue and Salwa (LEVEL 3).  There should be a Subtotal for each group of the agent. For example:-May (Agent) is the agent under Sarah (UM) and both of them have productivity and productivity should be sum up as a subtotal for the core group. A GRAND TOTAL is required to summarize all the productivity for each group.

    Problem: -.

    1. The output of my query is appear the subtotal, but the amount is inaccurate because it only to summarize the productivity of agent. The output I expect is summarize the productivity of the agent as well as UNIFIED messaging / AM. For example:-(subtotal = UM / AM.) THE PRODUCTIVITY + AGENT. PRODUCTIVITY)
    2. The total general does not show after the query. The output that I expected is productivity for each groups as shown in the attachment below.                                                   For example:- GRAND TOTAL =(SUBTOTAL+SUBTOTAL+SUBTOTAL)
    3. My data must be submitted in respect of the hierarchy as below: -.

    4. I need to pass the variable in the query and be used as a parameter in the ADF. Agent ID of Lily(AM) pass in the variable as a parameter.

    Here's my query: -.

    SELECT LPAD (' ', 4 *(LEVEL-1))

    || NAME FIRST_NAMEQ,

    TOTAL_MANPOWER,

    SUM_MTD_TOTAL_ANP UPSTREAM,

    level,

    A_AGENT_ID

    Of

    (SELECT B.SID,

    A.UPLINE,

    A.AGENT_ID AS A_AGENT_ID,

    GROUPING (B.SID) agg_am_id,

    GROUPING (A.AGENT_ID) agg_um_id,

    GROUPING (A.Upline) agg_IM_id,

    SUM (B.TOTAL_MANPOWER) TOTAL_MANPOWER,

    SUM (B.MTD_TOTAL_ANP) SUM_MTD_TOTAL_ANP

    OF ABM_AGENT_TEST,.

    ABM_PRODUCTIVITY B

    WHERE A.AGENT_ID = B.AGENT_ID

    ROLLUP GROUP ((A.UPLINE), (A.AGENT_ID, B.SID)))

    START WITH A_AGENT_ID =: HAS

    CONNECT BY PRIOR A_AGENT_ID = UPSTREAM

    ORDER OF FRIARS UPSTREAM;

    Below is the query to create the table and also the data: -.

    -TABLE ABM_AGENT_TEST-

    CREATE TABLE 'ABM_AGENT_TEST '.

    (NUMBER OF 'AGENT_ID',

    VARCHAR2 (50 BYTE) "NAME."

    VARCHAR2 (10 BYTE) "GRADE."

    VARCHAR2 (20 BYTE) "UPSTREAM."

    'REGION' VARCHAR2 (20 BYTE),

    "BRANCH" VARCHAR2 (20 BYTE),

    'THE AGENCY' VARCHAR2 (20 BYTE)

    )

    SAMPLE DATA FROM ABM_AGENT_TEST

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (116, "Lily", "AM", null, null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (102, 'Tom', 'MU', '116', null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (110, 'Sarah', 'MU', '116', null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (100, 'John', 'AGENT', '102', 'Central', 'PJ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (109, "Salwa", 'AGENT', '102', 'South', 'MLK', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (101, 'Howard', 'AGENT', '102', 'North', "Damansara", "AP");

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (103, 'Mary', 'AGENT', '102', 'Central', 'PJ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (106, 'Ali', 'AGENT', '110', 'Central', 'JlnPd', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (111, 'Sue', 'AGENT', '102', 'North', "Damansara", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (112, "Carron', 'AGENT', '102', 'Central', 'HQ', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (113, "Siti', 'AGENT', '102', 'Central', 'PJ', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (114, "Siti FHIMA Dane forecastle', 'AGENT', '102', 'North',"Damansara", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (105, 'Kathy', 'AGENT', '102', 'Central', 'JlnPd', 'LPK');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (107, 'Roby', 'AGENT', '110', 'North', "IPH", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (108, 'Tommy', 'AGENT', '110', 'South', 'MLK', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (104, 'May', 'AGENT', '110', 'Central', 'HQ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (115, 'Kevin', 'AGENT', '116', 'North', "IPH", null);

    -TABLE ABM_PRODUCTIVITY-

    CREATE TABLE 'JEROMEWALTER '. "" ABM_PRODUCTIVITY ".

    (NUMBER OF 'AGENT_ID',

    NUMBER OF "TOTAL_MANPOWER."

    NUMBER OF "MTD_TOTAL_ANP."

    NUMBER OF "MTD_PRODUCTIVITY."

    VARCHAR2 (20 CHAR) "YTD_TOTAL_ANP."

    VARCHAR2 (20 CHAR) "YTD_PRODUCTIVITY."

    "ROW_ID" VARCHAR2 (20 BYTE)

    )

    SAMPLE DATA FOR ABM_PRODUCTIVITY

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (104,1,85000, null, '40000', null, ' 6');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (102,1,35000, null, '33000', null, ' 7');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (110,1,25000, null, '25000', null, ' 8');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (116,1,22000, null, '34000', null, ' 10');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (109,1,75000, null, '80000', null, ' 2');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (111,1,25000, null, '25000', null, ' 3');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (100,1,23000, null, ' 34500', null, "11");

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (115,1,24000, null, '45000', null, ' 9');

    The output after having received the request and not as my are expected as below: -.

    The result I have espect is as below: -.

    If all goes well, there is a way to solve my question.

    Thank you all and have a nice day

    Hello

    I still don't know how you want to trunking.  You want someone who has a tank of 'AGENT' that lie with its parent in the hierarchy?

    If Yes, you can do the update ROLLUP before you make the CONNECT BY query and claim that summaries are the children of one of the actual lines in the tree, like this:

    WITH got_grp_id AS

    (

    SELECT b.SID, a.upline

    TO_CHAR (a.agent_id) AS a_agent_id

    CASE

    WHEN a.agent_rank = "AGENT".

    AND a.upline IS NOT NULL

    THEN a.upline

    Of OTHER TO_CHAR (a.agent_id)

    END AS grp_id

    p.total_manpower, p.mtd_total_anp

    Of abm_agent_test one

    abm_productivity p

    WHERE a.agent_id = p.agent_id

    )

    got_aggregates AS

    (

    SELECT THE CHECK BOX

    WHEN you GROUP (name) = 0

    THEN the name

    WHEN you GROUP (grp_id) = 0

    THEN "SUBTOTAL".

    ANOTHER "GRAND TOTAL".

    END AS name_s

    CASE

    WHEN you GROUP (upstream) = 0

    THEN upstream

    WHEN you GROUP (grp_id) = 1

    THEN TO_CHAR (: a).

    Of OTHER LAST_VALUE (a_agent_id IGNORE NULLS)

    COURSES (PARTITION BY grp_id

    ORDER OF CASES

    WHEN a_agent_id <> grp_id

    THEN SUM (mtd_total_anp)

    END NULLS FIRST

    ROWS BETWEEN UNBOUNDED PRECEDING

    AND UNBOUNDED FOLLOWING

    )

    END AS parent

    a_agent_id, grp_id

    SUM (total_manpower) AS sum_total_manpower

    SUM (mtd_total_anp) AS sum_mtd_total_anp

    Group of (name) AS g_name

    GROUPING (grp_id) AS g_grp_id

    OF got_grp_id

    GROUP OF ROLLUP (grp_id

    , (name, upstream, a_agent_id)

    )

    )

    SELECT THE CHECK BOX

    WHEN g_grp_id = 0

    THEN LPAD (' ', 4 * (LEVEL - 1))

    END | name_s AS first_nameq

    sum_total_manpower

    sum_mtd_total_anp

    CASE

    WHEN g_name = 0

    THEN THE LEVEL

    4 SOMETHING ELSE

    END as lvl

    a_agent_id

    OF got_aggregates

    START WITH a_agent_id = TO_CHAR (: a).

    Parent = a_agent_id PRIOR CONNECTION

    Brothers and SŒURS of ORDER BY sum_mtd_total_anp

    ;

    Output:

    SUM_

    SUM_ MTD_ A_

    TOTAL_ AGENT TOTAL

    FIRST_NAMEQ MANPOWER _ANP LVL _ID

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

    Lily 1 22000 1 116

    Kevin 1 24000 2 115

    PARTIAL TOTAL 2 46000 4

    Sarah 1 25000 2 110

    May 1 85000 3 104

    PARTIAL TOTAL 2 110000 4

    Tom 1 35000 2 102

    John 1 23000 3 100

    Sue 1 25000 3 111

    Salwa 1 75000 3 109

    PARTIAL TOTAL 4 158000 4

    GRAND TOTAL 8 314000 4

    I changed the column names.  (For example, there is a built-in function called RANK, so this isn't a column name good.  "It's confusing to use upstream to 2 unrealted stuff.)

    I guess just what you want for the LVL column.

    Why is agent_id a NUMBER, but upstream a VARCHAR2?  I expect to be of the same data type, so that upstream may be a foreign key referencing agent_id.

  • What is the equivalent of | operator using the Q-quote mechanism?

    Version: 11.2.0.3

    I started a thread on similar requirement last week. I didn't want to resurrect. So, I start a new thread.

    We have a stored procedure called generate_table_stats that meet the stats for tables with a few additional options.

    Usually, this procedure is performed as below

    generate_table_stats exec ('EMP_DTL', 'BASIC');

    We want to generate the exec above instructions dynamically for all tables.

    In the traditional method of quotations, we use the concatenation (|) operator to separate the column names whose values are retrieved dynamically from the table queried.

    Similarly, how can I get a column of values printed when you use the Q-quote mechanism?

    In my column in table_name attempt below must be retrieved from user_tables. But table_name and pipes that are treated as literal string (which is not surprising).

    What is the equivalent of | (concatenation operator) when you use the Q-quote mechanism?

    -Expected results

    generate_table_stats exec ('EMP_DTL', 'BASIC');

    generate_table_stats exec ('CUSTOMER_DTL', 'BASIC');

    .

    .

    .

    -My attempt using Q-quote

    -Using # as the quote delimiter

    SQL > select q'#exec generate_table_stats ('| table_name |', 'BASE'); #' From user_tables;

    Q' #EXECGENERATE_TABLE_STATS('||) TABLE_NAME |', 'BASE')

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

    generate_table_stats exec ('| table_name |', 'BASE');

    generate_table_stats exec ('| table_name |', 'BASE');

    generate_table_stats exec ('| table_name |', 'BASE');

    generate_table_stats exec ('| table_name |', 'BASE');

    .

    .

    .

    .

    Hello

    The concatenation operator. works the same with any string expression.

    x | There

    Returns a string that is the same as sting followed immediately the string x y, x is

    • a literal string with Q before the first single quote
    • a literal string without Q
    • a VARCHAR2 column
    • a function that returns a string, or
    • any string expression.

    The string can be everything above, too.

    If you concatenate strings of 3 or more, like this

    str1. str2. ... || Suro

    then each of the STRS can be any kind of expression, independent of others.

    If you want to concatenate strings of 3, the 1st and the 3rd being Q-literals and the 2nd being a column, you can do it like this:

    Select q' generate_table_stats #exec (#' | table_name)

    || q ' #, ' BASIC'); #'

    From user_tables;

    Each of literals has its own Q and her own pair of start and end markers (all the ' # s in the example above).

    Since the first string literal has no any single-quotation marks incorporated, it is unnecessary to use Q-rating, and it could be misleading; a person who bed the code might think the actaully string contains ' #'s.  I prefer wriite the query in the form

    Select ' generate_table_stats exec (' | table_name)

    || q ' #, ' BASIC'); #'

    From user_tables;

  • Max and sum in a query using Group by and dense_rank

    Hi all

    I am running Oracle 10 G on Windows 2003.

    I have two tables, RT_DY_ZONE1EDYCONS and MV_ZONE_HOURLY. I need a query that will give me the SUM of MR_OL01_VT of RT_DY_ZONE1EDYCONS for each month and the maximum value of MR_OL01_FI_0S and MR_OL02_FI_0S and the time of the maximum value for each group for the month of MV_ZONE_HOURLY. I can't combine the two querys I came up with these forums in a single search.

    I need the following result, any help would be appreciated.
    datetime, SUM of MR_OL01_VT , max value MR_OL01_FI_0S ,max_time MR_OL01_FI_0S , max value MR_OL02_FI_0S ,max_time MR_OL02_FI_0S
    January 2010,8.373765,4.96935,2010-01-15:01,5.96835,2010-01-15:17
    I used the following query to obtain the SUM of the MR_OL01_VT
    SELECT 
        TRUNC(VOL.TIMESTAMP, 'MM') datetime, 
        SUM(VOL.MR_OL01_VT) 
    FROM 
        RT_DY_ZONE1EDYCONS VOL 
    GROUP BY 
        TRUNC(VOL.TIMESTAMP, 'MM')
    ORDER BY
        TRUNC(VOL.TIMESTAMP, 'MM')
    and this query for the maximum value/time MR_OL01_FI_0S and MR_OL02_FI_0S
    select TAG_NAME,
           max(tag_avg) keep (dense_rank last order by tag_avg) over (partition by tag_name) Max_Value,
           max(datetime) keep (dense_rank last order by tag_avg) over (partition by tag_name) AS MAX_DATE
    from mv_zone_hourly
    WHERE tag_name LIKE 'MR_OL0%_FI_0S'
    first table
    CREATE TABLE RT_DY_ZONE1EDYCONS 
       (     TIMESTAMP DATE NOT NULL ENABLE, 
         HB_OL00_VT NUMBER(12,6), 
         OR_RES0_VT NUMBER(12,6), 
         OP_OL01_VT NUMBER(12,6), 
         FP_OL01_VT NUMBER(12,6), 
         BD_OL01_VT NUMBER(12,6), 
         MR_OL01_VT NUMBER(12,6), 
         Z1E_VT NUMBER(12,6)
    )
    with the sample data
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:00','YYYY-MM-DD:HH24'),4.443056,1.088,1.224927,0.663266,0,0.387499,1.079364);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:01','YYYY-MM-DD:HH24'),4.352083,null,0.692914,0.044029,0,0.373536,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:02','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:03','YYYY-MM-DD:HH24'),4.300694,null,0.662924,0,0,0.380275,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:04','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:05','YYYY-MM-DD:HH24'),0.025694,null,0.650406,0,0,0.342299,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:06','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:07','YYYY-MM-DD:HH24'),0.122917,-2.992,0.673062,0,0,0.423474,2.018381);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:08','YYYY-MM-DD:HH24'),0.106944,null,1.27403,0.768119,0,0.449303,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:09','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:10','YYYY-MM-DD:HH24'),0.122917,-2.448,0.637977,0,0,0.418056,1.514884);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:11','YYYY-MM-DD:HH24'),0.183333,-2.992,0.649855,0,0,0.401947,2.123531);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:12','YYYY-MM-DD:HH24'),1.157639,-2.992,1.039931,0.463684,0,0.43389,2.212134);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:13','YYYY-MM-DD:HH24'),4.536111,1.36,0.972226,0.381604,0,0.461941,1.36034);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:14','YYYY-MM-DD:HH24'),4.496528,2.176,0.647979,0,0,0.45611,1.216439);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:15','YYYY-MM-DD:HH24'),4.409028,2.72,0.665355,0,0,0.440141,0.583532);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:16','YYYY-MM-DD:HH24'),4.380556,1.36,0.886389,0.256387,0,0.429446,1.448334);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:17','YYYY-MM-DD:HH24'),4.433333,0.272,1.21716,0.656324,0,0.434169,1.85368);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:18','YYYY-MM-DD:HH24'),4.409722,2.176,0.653266,0,0,0.436253,1.144203);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:19','YYYY-MM-DD:HH24'),4.44375,2.448,0.67917,0,0,0.436947,0.879633);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:20','YYYY-MM-DD:HH24'),4.420833,0,1.273057,0.733813,0,0.428474,1.985489);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:21','YYYY-MM-DD:HH24'),4.390278,2.176,0.895212,0.280419,0,0.418195,0.620452);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:22','YYYY-MM-DD:HH24'),4.336806,1.904,0.670843,0,0,0.412711,1.349252);
    Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:23','YYYY-MM-DD:HH24'),4.305556,2.448,0.689441,0,0,0.409099,0.759016);
    and the second table
    CREATE TABLE MV_ZONE_HOURLY
    ( TAG_NAME VARCHAR2(30),
      TAG_DESCRIP VARCHAR(100),
      DATETIME DATE,
      TAG_AVG NUMBER(12,6)
    )
    with the sample data
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:00','YYYY-MM-DD:HH24'),4.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:01','YYYY-MM-DD:HH24'),4.96935);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:02','YYYY-MM-DD:HH24'),4.367);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:03','YYYY-MM-DD:HH24'),4.67788);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:04','YYYY-MM-DD:HH24'),4.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:05','YYYY-MM-DD:HH24'),3.23456);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:06','YYYY-MM-DD:HH24'),4.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:07','YYYY-MM-DD:HH24'),4.5890);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:08','YYYY-MM-DD:HH24'),4.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:09','YYYY-MM-DD:HH24'),4.96735);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:10','YYYY-MM-DD:HH24'),4.8456);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:11','YYYY-MM-DD:HH24'),4.2468);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:12','YYYY-MM-DD:HH24'),4.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:13','YYYY-MM-DD:HH24'),3.9746);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:14','YYYY-MM-DD:HH24'),4.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:15','YYYY-MM-DD:HH24'),4.47);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:16','YYYY-MM-DD:HH24'),4.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:17','YYYY-MM-DD:HH24'),4.96835);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:18','YYYY-MM-DD:HH24'),4.6890);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:19','YYYY-MM-DD:HH24'),4.42345);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:20','YYYY-MM-DD:HH24'),4.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:21','YYYY-MM-DD:HH24'),3.4579);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:22','YYYY-MM-DD:HH24'),4.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:23','YYYY-MM-DD:HH24'),4.45789);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:00','YYYY-MM-DD:HH24'),5.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:01','YYYY-MM-DD:HH24'),5.97835);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:02','YYYY-MM-DD:HH24'),5.367);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:03','YYYY-MM-DD:HH24'),5.67788);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:04','YYYY-MM-DD:HH24'),5.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:05','YYYY-MM-DD:HH24'),4.23456);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:06','YYYY-MM-DD:HH24'),5.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:07','YYYY-MM-DD:HH24'),5.5890);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:08','YYYY-MM-DD:HH24'),5.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:09','YYYY-MM-DD:HH24'),5.95635);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:10','YYYY-MM-DD:HH24'),5.8456);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:11','YYYY-MM-DD:HH24'),5.2468);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:12','YYYY-MM-DD:HH24'),5.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:13','YYYY-MM-DD:HH24'),4.9746);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:14','YYYY-MM-DD:HH24'),5.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:15','YYYY-MM-DD:HH24'),5.47);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:16','YYYY-MM-DD:HH24'),5.166712);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:17','YYYY-MM-DD:HH24'),5.96835);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:18','YYYY-MM-DD:HH24'),5.6890);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:19','YYYY-MM-DD:HH24'),5.42345);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:20','YYYY-MM-DD:HH24'),5.06335);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:21','YYYY-MM-DD:HH24'),4.4579);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:22','YYYY-MM-DD:HH24'),5.2333555);
    Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:23','YYYY-MM-DD:HH24'),5.45789);

    Hello

    Thanks for posting the CREATE TABLE and INSERT statements; This is really useful!

    Your volumninous sample data are all for a month. Since your first query is grouped by month, I suppose that this is not always the case.
    In this case, you can make GROUP BY queries on two tables separately, in two subqueries, then join the results.
    For the separate columns for the values of mv_zone_hoiurly, I GROUP BY the name of tag in the subquery, then their pivot in two columns in the query of amin.

    WITH     edycons_summary       AS
    (
         SELECT       TRUNC (tmstmp, 'MM')     AS mnth
         ,       SUM (mr_ol01_vt)     AS sum_mr_ol01_vt
         FROM       rt_dy_zone1edycons
         GROUP BY  TRUNC (tmstmp, 'MM')
    )
    ,     hourly_summary       AS
    (
         SELECT       tag_name
         ,       TRUNC (datetime, 'MM')     AS mnth
         ,       MAX (tag_avg)                  AS max_avg
         ,       MAX (datetime) KEEP (DENSE_RANK LAST ORDER BY tag_avg NULLS FIRST)
                                              AS max_avg_datetime
         FROM       mv_zone_hourly
         WHERE       tag_name     IN ( 'MR_OL01_FI_0S'
                             , 'MR_OL02_FI_0S'
                           )
         GROUP BY  tag_name
         ,            TRUNC (datetime, 'MM')
    )
    SELECT       TO_CHAR (v.mnth, 'fmMonth YYYY')     AS datetime
    ,       v.sum_mr_ol01_vt
    ,       MAX ( CASE
                     WHEN  h.tag_name = 'MR_OL01_FI_0S'
                  THEN  h.max_avg
                 END
               )                         AS max_avg_01
    ,       MAX ( CASE
                     WHEN  h.tag_name = 'MR_OL01_FI_0S'
                  THEN  h.max_avg_datetime
                 END
               )                         AS datetime_01
    ,       MAX ( CASE
                     WHEN  h.tag_name = 'MR_OL02_FI_0S'
                  THEN  h.max_avg
                 END
               )                         AS max_avg_02
    ,       MAX ( CASE
                     WHEN  h.tag_name = 'MR_OL02_FI_0S'
                  THEN  h.max_avg_datetime
                 END
               )                         AS datetime_02
    FROM       edycons_summary     v
    JOIN       hourly_summary     h     ON     h.mnth     = v.mnth
    GROUP BY  v.mnth
    ,            v.sum_mr_ol01_vt
    ;
    
  • separate account using the lookup table

    How can I get a separate count of column values by using another table?

    Let's say I want to get a separate account of all 'company_name' files in the 'emp' table that corespond (soccer match) with table of 'research', 'State' category.

    What I want is to find charges for all businesses that have a value of 'california' in the 'Status' column of the 'search' Table. I want the output to look like:

    Sears 17
    Pennys 22
    Marshalls 6
    Macys 9

    I want the result to show me the company names dynamically as I don't know what they are, just that they are part of the group 'State' in the lookup Table object. Does make sense?

    M

    If you want a counter for each value of rfs_category, but instead of rfs_category you want to display, it's translated value lookup_value_desc.

    This should do it for you:

    select lookup_value_desc, the_count
      from lookup
      join (select rfs_category, count(*) the_count
              from RFS group by rfs_category)
        on rfs_category = lookup_type;
    
  • How to use Group Policy to disable USB Internet dongles

    Dear MS,

    This is to request a solution about the use of group policy to disable USB Internet dongles and allow other USB devices like mice and keyboards in server 2008 R2. I tried several options but still, I'm having the problem. Kindly give me a solution as soon as possible.

    Hello

    Post your question in the TechNet Server Forums, as your question kindly is beyond the scope of these Forums.

    http://social.technet.Microsoft.com/forums/WindowsServer/en-us/home?category=WindowsServer

    See you soon.

  • Using groups of Windows Mail contacts without displaying the FIELD email addresses; and without having to use the BCC field?

    I want to see all the names of everyone in the group in the TO field: only the names of individuals in the Contact Group and NOT to display their individual addresses alongside their names; and I don't want to use the BCC field (because it will appear all the names). Is this possible?

    Unless you have included their address in a part of the field name, the addresses must disappears from view when sending. That said, all they need do is click on transfer, reply to all, or view the message source and they see all the addresses. That's why the BCC option was created. Bruce Hagen
    MS - MVP October 1, 2004 ~ September 30, 2010
    Imperial Beach, CA

  • How can I associate with other separate articles, using the publishing tools digital adobe?

    All items are collected in folio Builder. I know how to put a link in an article, but not to the other separate articles. I want to put a text link in the index of my magazine to the landing page. I have Indesign CC. Please, can you help me?

    This is correct to a links Panel example. You should check the shared button hyperlinks. This example goes to a specific page in an article. The article name should be the name of the article in Folio generator Panel. Your names are not similar there are spaces. Remove the spaces or use underscores.

    Here is an example of a button. You use go to URL not go to Destination.

    The navto coding convention is the same for the buttons and hyperlinks.

Maybe you are looking for