I need assistance of query SQL, a query to get the same without union clause

EmpNo, ename sum (sal) sum (deptno)
200-2000-10 Tom
201 3000 10 smith
Alfred 202 20 3000
40 8000 total
select NVL(TO_CHAR(employee_id), 'Total'),
       max(last_name),
       sum(salary),
       sum(department_id)
  from employees
 group by rollup(employee_id), ()

Tags: Database

Similar Questions

  • Can do us a query to get the same results of 3 tables

    CREATE TABLE TABLE1 (NODEID VARCHAR2 (4));
    CREATE TABLE TABLE2 (NODEID VARCHAR2 (4));
    CREATE TABLE TABLE3 (NODEID VARCHAR2 (4));


    INSERT INTO TABLE1 VALUE('1004');
    INSERT INTO TABLE1 VALUE('1004');
    INSERT INTO TABLE1 VALUE('1002');
    INSERT INTO TABLE1 VALUE('1002');
    INSERT INTO TABLE1 VALUE('1001');
    INSERT INTO TABLE1 VALUE('1001');
    INSERT INTO TABLE1 VALUE('1006');
    INSERT INTO TABLE1 VALUE('1006');
    INSERT INTO TABLE1 VALUE('1005');
    INSERT INTO TABLE1 VALUE('1005');

    INSERT INTO TABLE2 VALUE('1004');
    INSERT INTO TABLE2 VALUE('1004');
    INSERT INTO TABLE2 VALUE('1004');
    INSERT INTO TABLE2 VALUE('1002');
    INSERT INTO TABLE2 VALUE('1002');
    INSERT INTO TABLE2 VALUE('1002');
    INSERT INTO TABLE2 VALUE('1002');

    INSERT INTO TABLE 3 VALUE('1001');
    INSERT INTO TABLE 3 VALUE('1001');
    INSERT INTO TABLE 3 VALUE('1006');
    INSERT INTO TABLE 3 VALUE('1006');
    INSERT INTO TABLE 3 VALUE('1005');
    INSERT INTO TABLE 3 VALUE('1005');
    INSERT INTO TABLE 3 VALUE('1004');
    INSERT INTO TABLE 3 VALUE('1004');
    INSERT INTO TABLE 3 VALUE('1004');
    INSERT INTO TABLE 3 VALUE('1002');
    INSERT INTO TABLE 3 VALUE('1002');
    INSERT INTO TABLE 3 VALUE('1002');
    INSERT INTO TABLE 3 VALUE('1002');

    SELECT count (*), count (distinct nodeid)
    of table1, table2, table3
    where table1.nodeid = table2.nodeid and table1.nodeid = table3.nodeid;


    SELECT count (*), count (distinct nodeid)
    FROM table1, table3
    where table1.nodeid = table2.nodeid;

    SELECT count (*), count (distinct nodeid)
    from table2, table3
    where table2.nodeid = table3.nodeid;
    SQL> SELECT MAX (CASE WHEN row_ind = 1 THEN ct END) ct_1,
      2         MAX (CASE WHEN row_ind = 1 THEN distinct_ct END) distinct_ct_1,
      3         MAX (CASE WHEN row_ind = 2 THEN ct END) ct_2,
      4         MAX (CASE WHEN row_ind = 2 THEN distinct_ct END) distinct_ct_2,
      5         MAX (CASE WHEN row_ind = 3 THEN ct END) ct_3,
      6         MAX (CASE WHEN row_ind = 3 THEN distinct_ct END) distinct_ct_3
      7    FROM (SELECT 1 AS row_ind,
      8                 COUNT (*) ct,
      9                 COUNT (DISTINCT table1.nodeid) distinct_ct
     10            FROM table1, table2, table3
     11           WHERE table1.nodeid = table2.nodeid
     12                 AND table1.nodeid = table3.nodeid
     13          UNION ALL
     14          SELECT 2 AS row_ind, COUNT (*), COUNT (DISTINCT table1.nodeid)
     15            FROM table1, table3
     16           WHERE table1.nodeid = table3.nodeid
     17          UNION ALL
     18          SELECT 3 AS row_ind, COUNT (*), COUNT (DISTINCT table2.nodeid)
     19            FROM table2, table3
     20           WHERE table2.nodeid = table3.nodeid)
     21  /
    
          CT_1 DISTINCT_CT_1       CT_2 DISTINCT_CT_2       CT_3 DISTINCT_CT_3
    ---------- ------------- ---------- ------------- ---------- -------------
            50             2         26             5         25             2
    

    There may be an easier way...

  • (WRT54G) I need to set it up so that I get the same IP all the time for 1 computer on my network.

    I have 4 computer I have linked to the WRT54G. 2 2 with network cables and wireless. One of these computers I use as a server and I would get the same IP address to the server all the time. As 192.168.1.150. Now it depends on when I turn on my computer what IP they get. Is there a way to get a static IP address?

    Glenn (phonograph)


  • SQL query to get the NULL records after the last matching flag

    I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).

    SQL > create table xx1

    2 (identification number,

    3 flag varchar2 (10));

    Table created.

    SQL > insert into xx1 values (1, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (2, null);

    1 line of creation.

    SQL > insert into values xx1 (3, null);

    1 line of creation.

    SQL > insert into xx1 values (4, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (5, null);

    1 line of creation.

    SQL > insert into xx1 values (6, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (7, null);

    1 line of creation.

    SQL > insert into values xx1 (8, null);

    1 line of creation.

    SQL > insert into values xx1 (9, null);

    1 line of creation.

    SQL > select * from xx1.

    FLAG OF THE ID

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

    1. IS

    2

    3

    4. IS

    5

    6. IS

    7

    8

    9

    9 selected lines.

    SQL >

    Hello

    user11164339 wrote:

    Hi Frank - when I run the query, I don't see the results data.

    I get

    FLAG OF THE ID

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

    7

    8

    9

    What you do differently?

  • IOM sql Query to get the status of the failed task

    Hello world

    We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.

    Thanks in advance.

    Kind regards
    MKN

    Hello
    Use this query to get the status of the task, also check the cooments

    SELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
    OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
    WHERE OSI.MIL_KEY = MIL.MIL_KEY
    AND ANN. SCH_KEY = OSI. SCH_KEY
    AND STA. STA_STATUS = SCH. SCH_STATUS
    AND TOS. PKG_KEY = PKG. PKG_KEY
    AND MIL. TOS_KEY = TOS. TOS_KEY
    AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
    AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
    AND OST. OBJ_KEY = OBJ. OBJ_KEY
    AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
    AND OBJ. OBJ_NAME = "User AD".
    AND OST. OST_STATUS = "Provisioning" - filter accordinglly
    AND STA. STA_BUCKET = 'pending' - filter accordinglly
    AND PKG. PKG_NAME = "AD User" - filter accordinglly
    AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
    ;
    Thank you
    Kuldeep

  • Need help with query to get days of work there are using the calendar BOM

    RDBMS: 10.2.0.4.0
    Oracle Applications: 11.5.10.2

    I try to use the BOM existing in the EBS to calculate working days calendar, there is a report that I am train. The BOM calendar presents the working days and non-working with the weekend days and holidays listed as non-working days. The following query gives correct results, but I'm looking for two different ways to do the same without "the union. I have nothing against the "unions", but I feel that I'm missing a more elegant to get there way. The query will in Discoverer Plus 10.1.2.3, so using a statement 'By' is not supported.
    sample data
    
    calendar_code                calendar_date                 seq_num                     
    SAC-WRKDAY                   12/3/2010                     1817
    SAC-WRKDAY                   12/4/2010                                                              
    SAC-WRKDAY                   12/5/2010                                                              
    SAC-WRKDAY                   12/6/2010                     1818                                 
    SAC-WRKDAY                   12/7/2010                     1819                                 
    SAC-WRKDAY                   12/8/2010                     1820     
    SAC-WRKDAY                   12/9/2010                     1821
    SAC-WRKDAY                   12/10/2010                    1822
    SAC-WRKDAY                   12/11/2010                   
    SAC-WRKDAY                   12/12/2010
    SAC-WRKDAY                   12/13/2010                    1823             
    select calendar_code
         , calendar_date
         , seq_num
         , sum(decode(bcd.seq_num,null,0,1))over(partition by bcd.calendar_code order by bcd.calendar_date desc) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'     
    and    trunc(bcd.calendar_date) < trunc(sysdate)
    
    union
    
    select calendar_code
         , calendar_date
         , seq_num
         , -sum(decode(bcd.seq_num,null,0,1))over(partition by bcd.calendar_code order by bcd.calendar_date ) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'
    and    trunc(bcd.calendar_date) > trunc(sysdate)
    sample output
    
    calendar_code                calendar_date                 seq_num                      workdays_ago
    SAC-WRKDAY                   12/3/2010                     1817                                  3
    SAC-WRKDAY                   12/4/2010                                                           2
    SAC-WRKDAY                   12/5/2010                                                           2
    SAC-WRKDAY                   12/6/2010                     1818                                  2
    SAC-WRKDAY                   12/7/2010                     1819                                  1
    SAC-WRKDAY                   12/9/2010                     1821                                 -1
    SAC-WRKDAY                   12/10/2010                    1822                                 -2
    SAC-WRKDAY                   12/11/2010                                                         -2
    SAC-WRKDAY                   12/12/2010                                                         -2
    SAC-WRKDAY                   12/13/2010                    1823                                 -3

    Hello

    Of course, you should be able to combine these queries, something like this:

    select calendar_code
         , calendar_date
         , seq_num
         , sum ( CASE
               WHEN  bcd.seq_num IS NULL
               THEN  0
               WHEN  bcd.calendar_date < TRUNC (SYSDATE)
               THEN  1
               ELSE  -1
              END
            ) over ( partition by  bcd.calendar_code
                  ,            SIGN (SYSDATE - bcd.calendar_date)
                  order by        ABS  (SYSDATE - bcd.calendar_date)
                ) workdays_ago
    from   bom.bom_calendar_dates bcd
    where  calendar_code = 'SAC-WRKDAY'
    and    trunc(bcd.calendar_date) < trunc(sysdate)
    

    If you do not want to display some CREATE TABLE and INSERT statements for the sample data, and then I could test it.

    t_norwillo wrote:
    ... I have nothing against the "unions", but I feel that I'm missing a more elegant to get there way.

    Good thinking!
    When the two branches of the UNION query the same table, there is usually a more effective way: something that only requires a pass through the table.

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • Query to get the data of the column and the metadata in the same set of results.

    Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.

    If I use a join, have a common value to join on the two tables?

    you use a cross join, not requiring common values.

    create table T (n number, d date, v varchar2(30));
    insert into T values (1,sysdate,'ABC');
    commit;
    
    select C.column_name, c.data_type, c.data_length,
    case c.column_id
     when 1 then to_char(T.N)
     when 2 then to_char(T.D)
     when 3 then T.V
    end VALUE
    from USER_TAB_COLUMNS C, T
    where C.table_name='T'
    order by c.column_id;
    
  • Query with almost the same query as a subquery, can it be optimized?

    I have a query using almost a duplicate of itself (table 1) as a subquery, and I wonder if it can be rewritten better, like she just doesn't seem the right way to do it, but everything I try I can't get the same number of lines back.

    If anyone can see a better way, it would be a great help.

    Thank you very much
    SELECT t.pol_number||t.check_digit
    FROM   transactions t, policies p, funds f
    WHERE f.fnd_code = t.trn_fnd_code
    AND     t.trn_pol_number = p.pol_number
    AND     p.pol_status IN (1,2)
    AND     t.trn_status = 'NEW'
    AND     t.trn_trn_number IN
       (SELECT t2.trn_trn_number
        FROM   transactions t2, policies p2
        WHERE t2.trn_pol_number = p2.pol_number 
        AND     p2.pol_status IN (1,2)
        AND     t2.trn_status = 'NEW'
        AND     t2.trn_fnd_code = :PARAMETER)
    Surely it is not the best way to write it as you use the same table twice and restrictions?

    Published by: Scott Hillier on March 16, 2010 15:11

    It looks like you want all the lines of the siblings who do not personally meet the restriction on trn_fnd_code. You can use analytical functions;

    not tested

    select *
      from (select pol_number || check_digit col1,
                   max(case
                          when t.trn_fnd_code = :parameter then
                           1
                          else
                           0
                        end) over(partition by trn_trn_number) max_trn_number
              from transactions t, policies p, funds f
             where f.fnd_code = t.trn_fnd_code
               and p.pol_status in (1, 2)
               and t.trn_status = 'NEW')
     where max_trn_number = 1;
    
  • Tuning sql of a product to the seller without changing the sql statement

    Hello

    We have a product of the provider that generates the SQL statement. For a query, we get the answer in 15 seconds. But users are asking if we can bring it back to 5 seconds. Limitation is the query can not be changed. He used about 10 to 12 tables and bit complex query.

    What kind of options could be evaluated if we are to improve the performance of a query (not sure if she could never be reduced to 5 seconds)
    without making any change to the query.

    Database Version: Oracle 10.2.0.4

    Thank you
    Delphine

    Hello

    http://www.Oracle-base.com/articles/10G/AutomaticSQLTuning10g.php

    your software is enterprise or standard?

    Tuning Pack & pack diagnosis are extra cost option with the standard edition.

    & the useful note * automatic SQL Tuning - SQL [271196.1 ID] profiles *.

    http://www.Oracle.com/us/corporate/pricing/technology-price-list-070617.PDF

    Thank you

    Published by: CKPT November 5, 2010 11:12

  • Does not update, said prev version needs to update and restart. It of not, get the same error

    Old version of Firefox running. Tried to update and get the message that a previous version has not finished installing and computer needs to reboot to finish. I restart, then try to install the new version, but just get the same error. I also tried to uninstall and start again, but got the same exact message he needed to finish the update before it could be installed.
    Suggestions?
    Thank you!

    Do a cleaning (re) install and delete the folder of the program Firefox (C:\Program Files\Mozilla Firefox\).

    Download a new copy of Firefox and save the file to the desktop.

    Uninstall your current version of Firefox if possible.

    • Do NOT remove the data of a personal nature when you uninstall the current version or you lose your bookmarks and other data in the profile folder.

    Delete the program folder Firefox before installing newly downloaded copy of the Firefox installer.

    • It is important to remove the Firefox program folder to delete all the files and make sure that there is no problem with the files that were the remains after uninstallation.

    Your bookmarks and other profile data stored in the Firefox profile folder and will not be affected by a relocation, but make sure that you do not select delete data of a personal nature if you uninstall Firefox.

  • I have a laptop broke the rocovery disk not good ahy, I need the windows vista disk operating system how do I get the same themes?

    I have a laptop broke the rocovery disk not good ahy, I need the windows vista disk operating system how do I get the same themes?

    If Windows Vista was preinstalled on your computer, contact the manufacturer of your computer for a replacement CD. If you purchased a retail version of Windows Vista, contact Microsoft.

    This article in the Microsoft Knowledge Base has the details: How to replace Microsoft software or hardware, order service packs and updates of product and replace product manuals . Boulder computer Maven
    Most Microsoft Valuable Professional

  • I need to reload of Photoshop CS4 and I get the error: "License has stopped working" error message 6. -What this means and how can I solve this problem?

    I need to reload of Photoshop CS4 and I get the error: "License has stopped working" error message 6. -What this means and how can I solve this problem?

    Hello

    Please see error: "License has stopped working". Windows or error: "License has stopped working". Mac OS depending on the operating system you have.

    Hope that helps!

    Kind regards

    Sheena

  • I am a member creative cloud. I want to install the same applications from my laptop to my new desktop computer. I need to purchase another license? otherwise how do the same thing for my new desktop computer

    I am a member creative cloud. I want to install the same applications from my laptop to my new desktop computer. I need to purchase another license? otherwise how do the same thing for my new desktop computer

    I have it! Thank you

  • I currently have Lightroom 3. Do I need to download all intermediate versions before you get the latest version?

    I currently have Lightroom 3. Do I need to download all intermediate versions before you get the latest version?

    N ° just install the latest version. It does not rely on previous versions being installed.

Maybe you are looking for