How can I use SUM function to calculate # of employees in the comp.&deptnt?

I've got two tables: employee & department. I am trying to calculate total employees by department and total employees by the entire company. I know I need to use SUM function, but I only can calculate total employees by department & by company separately. I need to get this output:
DEPT_NAME     DEPT_TOTAL_SALARY         COMPANY_TOTAL_SALARY
RESEARCH                  10875                        29025
SALES                      9400                        29025   
ACCOUNTING                 8750                        29025     
This is my code:
SELECT department_name, SUM(salary) as total_salary
FROM employee, department
WHERE employee.department_id = department.department_id
GROUP BY department_name;
SELECT SUM(salary)
FROM employee;
Can somebody help please?
Thank you in advance.Edited by: user13675672 on Jan 30, 2011 2:29 PM
Edited by: user13675672 on Jan 30, 2011 2:31 PM

Hi, Peter
Peter Gjelstrup wrote:
... There might be a smarter way, with no re-select.You're right, as usual.
SELECT       d.dname
,       SUM (e.sal)               AS dept_tot_sal
,       SUM (SUM (e.sal)) OVER ()     AS comp_tot_sal
FROM       scott.dept     d
JOIN       scott.emp     e  ON     d.deptno     = e.deptno
GROUP BY  d.dname
;Analytic functions are computed after aggregate functions, so an aggregate function can be nested inside an analytic function.
Another way (without a sub-query, at least) would be SELECT DISTINCT, with only analytic functions.
SELECT DISTINCT
       d.dname
,       SUM (e.sal) OVER (PARTITION BY  d.dname)     AS dept_tot_sal
,       SUM (e.sal) OVER ()                    AS comp_tot_sal
FROM       scott.dept     d
JOIN       scott.emp     e  ON     d.deptno     = e.deptno
;

Similar Messages

  • How can i use SUM aggregate in select query?

    HI,
    GURUS,
    How can i use SUM function in Select Query and i want to store that value into itab.
    for ex:
    TABLES: vbap.
    types: begin of ty_vbap,
           incluse type vbap,
           sum type string,
          end of ty_vbap.
    data: i_vbap type TABLE OF ty_vbap,
          w_vbap type ty_vbap.
    SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
                            (or)
    SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
      loop at i_vbap into w_vbap
    " which variable have to use to display summed value.
      endloop.
    if above code is not understandable pleas give ome sample code on  above query.
    Thank u,
    shabeer ahmed.

    Hi,
    Check this sample code.
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Regards,
    Sravanthi

  • How can i use this  function module

    Hai
    How can i use this function module /SAPHT/SALES_ORDER_READ, already apply the some parameters in this function module, but it shows the error , please tell me, how to declare the parameters in this function module ,
    thanks
    neelima

    Hi
    For a particular sales order,you have to pass the order number and the item number in the sales order.
    It will display the rest of the values which u can capture them using internal tables.
    Regards,
    Vishwa.

  • How can i use reuse_alv_fieldcatalog_merge function module

    I am using below steps for populating the final internal table.How can I use reuse_alv_fieldcatalog_merge function module in the place of declaring all these fields.How canI put title of the report in reuse_alv_fieldcatalog_merge function module.
    FORM BUILD_FIELDCATALOG .
      FIELDCAT-TABNAME   = 'IT_FINAL'.
      FIELDCAT-FIELDNAME = 'KUNNR'.
      FIELDCAT-SELTEXT_M = 'Customer Name'.
      FIELDCAT-JUST      = 'L'.
      FIELDCAT-KEY       = 'X'.
      FIELDCAT-DATATYPE  = 'C'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.
      FIELDCAT-TABNAME   = 'IT_FINAL'.
      FIELDCAT-FIELDNAME = 'VBELN'.
      FIELDCAT-SELTEXT_M = 'Invoice Reference'.
      FIELDCAT-JUST      = 'L'.
      FIELDCAT-KEY       = 'X'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.
      FIELDCAT-TABNAME   = 'IT_FINAL'.
      FIELDCAT-FIELDNAME = 'VKBUR'.
      FIELDCAT-SELTEXT_M = 'Sales Office'.
      FIELDCAT-JUST      = 'L'.
    FIELDCAT-KEY       = 'X'.
      FIELDCAT-DATATYPE  = 'C'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.
      FIELDCAT-TABNAME   = 'IT_FINAL'.
      FIELDCAT-FIELDNAME = 'VKGRP'.
      FIELDCAT-SELTEXT_M = 'Sales Person'.
      FIELDCAT-JUST      = 'L'.
    FIELDCAT-KEY       = 'X'.
      FIELDCAT-DATATYPE  = 'C'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.
      FIELDCAT-TABNAME   = 'IT_FINAL'.
      FIELDCAT-FIELDNAME = 'POSNR'.
      FIELDCAT-SELTEXT_M = 'Item No'.
      FIELDCAT-JUST      = 'L'.
      FIELDCAT-KEY       = 'X'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.
      FIELDCAT-TABNAME   = 'IT_FIANL'.
      FIELDCAT-FIELDNAME = 'ARKTX'.
      FIELDCAT-SELTEXT_M = 'Item Description'.
      FIELDCAT-JUST      = 'L'.
      FIELDCAT-DATATYPE  = 'C'.
      APPEND FIELDCAT TO I_FIELDCAT.
      CLEAR FIELDCAT.

    Hello,
    It is very easy to use reuse_alv_fieldcatalog_merge.
    You try this it will work.
    example
    data:
    DATA : gv_repid        TYPE syrepid VALUE sy-repid .  " Report id
      PERFORM set_field_catalog USING gst_struct CHANGING lst_fieldcat.
    FORM set_field_catalog  USING uv_tab TYPE slis_tabname
                         CHANGING  xt_fieldcatalog TYPE slis_t_fieldcat_alv.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = gv_repid
          i_internal_tabname     = uv_tab
          i_inclname             = gv_repid
        CHANGING
          ct_fieldcat            = xt_fieldcatalog
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " set_field_catalog_spec

  • How can I use 3D function in Photoshop CS6 (student package)?

    Please let me know how can I use 3D function in Photoshop CS6 (student package)?
    Thanks,

    Thanks so much for your helpful reply.
    Now I' ve already installed Adobe Creative Suite 6 Production Premium (Student Package), Extended included. But when I open Photoshop CS6, there' s still no 3D function in menu bar.
    Would you please tell me how to activate this function?
    Thanks,

  • How can I have both functions "Read Only" & "Write" mode on the same form?

    Dear all,
    How can I have both functions "Read Only" & "Write" mode on the same form? Is it possibile for this?
    Please advice,
    Amy

    This is what I use in some dialogs:
    PROCEDURE SET_QUERY_ONLY IS
      -- Procedure Set_query_only
      -- Rend les blocks non modifiables   --
      -- Disable menus Insert/Delete/Clear --
      -- Entree               :
      -- Sortie               :
      -- Ent/Sortie     :
      -- Creation               : FD    10/2003
      -- Modification     : 
         LC$Block     Varchar2(30) ;
    BEGIN
      Set_Menu_Item_Property('Edit.Insert', ENABLED, PROPERTY_FALSE ) ;
      Set_Menu_Item_Property('Edit.Remove', ENABLED, PROPERTY_FALSE ) ;
      Set_Menu_Item_Property('Edit.Clear', ENABLED, PROPERTY_FALSE ) ;
      Set_Menu_Item_Property('Action.Save', ENABLED, PROPERTY_FALSE ) ;
      LC$Block := get_form_property( NAME_IN('System.Current_Form'), FIRST_BLOCK ) ;
      -- Tous les blocs en Query only --
      While LC$Block is not null Loop
           Enable_Block( LC$Block, FALSE ) ;
           LC$Block := get_block_property( LC$Block, NEXTBLOCK ) ;
      End loop ;
    END;
    PROCEDURE ENABLE_BLOCK
              PC$Block in Varchar2,
              PB$Enable in Boolean Default TRUE
         ) IS
      -- Procedure Enable_block
      -- Rend le bloc Enable / Disable --
      -- Entree          : PC$Block (nom du bloc Forms)
      --               : PB$Enable (TRUE ou FALSE)
      -- Sortie          :
      -- Ent/Sortie             :
      -- Creation          : FD    10/2003
      -- Modification     : 
    BEGIN
         If PB$Enable Then
              Set_Block_Property( PC$Block, INSERT_ALLOWED, PROPERTY_TRUE ) ;
              Set_Block_Property( PC$Block, UPDATE_ALLOWED, PROPERTY_TRUE ) ;
              Set_Block_Property( PC$Block, DELETE_ALLOWED, PROPERTY_TRUE ) ;
              Set_Menu_Item_Property('Edit.Insert', ENABLED, PROPERTY_TRUE ) ;
              Set_Menu_Item_Property('Edit.Remove', ENABLED, PROPERTY_TRUE ) ;
              Set_Menu_Item_Property('Edit.Clear', ENABLED, PROPERTY_TRUE ) ;
              Set_Menu_Item_Property('Action.Save', ENABLED, PROPERTY_TRUE ) ;
         Else
              Set_Block_Property( PC$Block, INSERT_ALLOWED, PROPERTY_FALSE ) ;
              Set_Block_Property( PC$Block, UPDATE_ALLOWED, PROPERTY_FALSE ) ;
              Set_Block_Property( PC$Block, DELETE_ALLOWED, PROPERTY_FALSE ) ;
              Set_Menu_Item_Property('Edit.Insert', ENABLED, PROPERTY_FALSE ) ;
              Set_Menu_Item_Property('Edit.Remove', ENABLED, PROPERTY_FALSE ) ;
              Set_Menu_Item_Property('Edit.Clear', ENABLED, PROPERTY_FALSE ) ;
              Set_Menu_Item_Property('Action.Save', ENABLED, PROPERTY_FALSE ) ;
         End if ;
    END;Francois

  • HT5437 How can I use apple TV to connect my computer to the tv screen as an external monitor?

    How can I use apple TV to connect my computer to the tv screen as an external monitor?

    Morning jotref,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at this article:
    About AirPlay Mirroring in OS X Mountain Lion
    http://support.apple.com/kb/ht5404
    Best of luck,
    Mario

  • HT1660 how can I use one single library for all users on the same laptop?

    how can I use one single library for all users on the same laptop?

    You are most of the way there. Each user having access to hard drive is the key. If users are limited in file privileges this is harder.
    Any files you add to your library and any files she adds to her library are available to the other. Just not automatically. Each user must add the files to their own library using the add file or add folder option from menu bar.
    What I have done is set library location to a location outside of My Documents\My Music. On my network storage I have a folder names s:\itunes. Both accounts iTunes are set to use this location for the library.

  • How can I use Guest network when my internal server provides the DNS?

    How can I use guest network when my internal server provides the DNS? The help article TS4505 tells me to enter an external DNS server, but I believe I can not configure my network that way...

    Apple assumes that you will be connecting the Time Capsule to a simple modem....and.....that the Time Capsule is configured as a router to provide DHCP and NAT services for the network.
    The Guest Network cannot be enabled correctly unless the Time Capsule is in charge of DHCP and NAT services on the network.
    Another way of saying the same thing is that the Guest Network will not operate correctly if the  Time Capsule is configured in Bridge Mode or DHCP Only.

  • My iphone 4s is 2nd ...then i format..the phone want old user id...how can i used that iphone back because i dont know the id?

    My iphone 4s is 2nd ...then i format..the phone want old user id...how can i used that iphone back because i dont know the id?

    There is no other solution - as you have already been told, if you don't have that user id and you cannot contact the previous owner of that id for the phone, then there is absolutely nothing that you can do.  You have a useless brick that you can't use.
    Nothing else to do.

  • How can i use a function in a create table?

    I have done one funtion to do one check in a create table statement, but i don't know where to use it. How can I use it?

    I have the function:
    CREATE OR REPLACE FUNCTION verificar_NIF (nif varchar2) return boolean as
    l_check_digit constant varchar2(23) := 'TRWAGMYFPDXBNJZSQVHLCKE';
    l_mod number;
    l_result varchar2(1);
    l_return boolean := false;
    begin
    l_mod := mod(substr(nif, 1, 8), 23);
    l_result := substr(l_check_digit, l_mod+1, 1);
    if l_result = substr(nif, 1, 9) then
    l_return := true;
    end if;
    return l_return;
    end;
    And I have the table:
    CREATE TABLE Clients (
         id_client NUMBER(5) PRIMARY KEY,
         nif VARCHAR2(9),
         cog1 VARCHAR2(50) NOT NULL,
         cog2 VARCHAR2(50) NOT NULL,
         nom VARCHAR2(50) NOT NULL,
         adre VARCHAR2(50) NOT NULL,
         Poblacio VARCHAR2(40) NOT NULL,
         CONSTRAINT err_NIF CHECK ( verificar_NIF(nif)=true )
    I want the var nif to have a concert value. It is correct to check in that way?

  • My employer is issuing an iPad 4 to me, but has informed me that I "...can expect no privacey" of any personal information that may be put on the iPad. This is not acceptable to me. How can I use iTunes to keep my personal information off the iPad?

    My employer is issuing an iPad 4 to me, but has informed me that "...I can expect no privacy" with regard to any information on it. What has me concerned is that my employer has also requested that I use my Persoanl iTunes account to syc and update the iPad.  I am concerend with my personal privacey, as I have two other iPads that use this account regualary.
    My question is: How can I use iTunes to update etc. the company iPad using iTunes without compromising my personal information?
    What I have done is to set up a different sign in (is that called an Apple ID?) within iTunes (I now have two different names I can use to sign in to iTunes). They both still use the same iTunes and my personal apps and information appear to be available to my second sign in name (the second sign in name is what I intend to use for the company iPad). When I sync the company iPad how do/can I keep my persoanl information from being syc'd automatically to the comapany iPad?

    Hi herbie13!
    It sounds like you will still want to link your iPad and computer, but you want to prevent the iPad from syncing information from your computer to your iPad. I have an article here for you that can help tell you how to set this up:
    iOS: Syncing with iTunes
    http://support.apple.com/kb/ht1386
    You will want to follow the steps here to set up the iPad for syncing, but when it comes time to sync, you'll just want to make sure that the boxes for syncing the multitude of items that you can sync remain unchecked so that none of that information gets synced into the iPad.
    Another note: your second Apple ID will not be able to access the apps, music, movies, tv shows, etc., that you have purchased under your primary Apple ID. Even though it seems that the secondary Apple ID still has access to those items, that is just because you are viewing your second Apple ID through the iTunes Store section on your computer and you have those items saved locally on your computer. You will need to repurchase and download all of the content that you wish to use again on your second Apple ID, if that is what you wish to solely use on this iPad.
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • I just moved from Germany back to the USA. How can I use an German iPhone6 from T-Mobile  in the USA

    I just moved from Germany back to the USA. How can I use an German iPhone 6 from T-Mobile  in the USA?

    Was your phone locked to T-Mobile? If so, it needs to be unlocked before you can use it here. I believe you can use it with AT&T or T-Mobile here, but you won't get 4G/LTE speeds.
    ~Lyssa

  • How can I use my Iphone 5s that was purchased in the US here in the Philippines?

    please let me know

    What do you mean how can you use the phone?  Go out and buy a sim card and put it in the phone to activate it and start using it.

  • How can I use AGO function with aggregates

    I use aggregated table and a detailed table
    I have time hierarchy whose lowest level is date. For sales I
    created year-to-year (YTD) comparision with AGO function. It
    works OK.
    BUT, I want to speed it up, so I used aggregates. I created new
    time table grouped by MONTH and corresponding agg_SALES table. I
    created connections and mapped the fields. It works OK for
    normal queries, that means my queries at month level use
    aggregates. BUT when I add YTD measures or YAGO measure in query, it goes to
    then SALES table whose grain is date.
    How can I force BI Server to use AGO function with aggregates?
    I use OBIEE 10.1.3.4
    Thank you
    Ishaq
    (Question originally taken from ITtoolbox and posted by Gorazd)
    SORRY - THE QUESTION IS IN THE WRONG FORUM
    Edited by: ishaq12 on Nov 19, 2008 12:21 PM

    Hi,
    you can not do it in Administration tool but you can set agregation for that field in Answers (fx->Agregation rule->Sum) and effect should be the same. Note that it may not work properly on Oracle 10g as generated SQL is not 100% recognized, on 11g everything is OK (at least in my case).
    Regards,
    Marko
    Edited by: user10449532 on 2008.11.19 06:29

Maybe you are looking for