How to calculate multiple aggregation in a single query

how to find firstname ,lastname for max and min salary from employees table group by department in a single query?
Edited by: Gnanasekar on Jan 10, 2012 6:36 AM

check this query
select ENAME,SAL
from EMP
where SAL in(select max(SAL)
                   from EMP
                  group by DEPTNO)
or SAL in(select min(SAL)
             from EMP
              group by DEPTNO)Hope this will help you..
You should ask this question at sql/plsql forum
If someone's response is helpful or correct, please mark it accordingly.

Similar Messages

  • How to insert multiple records in a single query

    Dear all,
    Can you please tell
    how to insert multiple records in a single query ??

    INSERT INTO table_name (column_1, column_2) VALUES ('value_A', 'value_B')OR
    INSERT INTO table_name
    (column_1, column_2)
    SELECT 'value_A', 'value_B' FROM DUAL
    UNION ALL
    SELECT 'value_C', 'value_D' FROM DUAL
    ;Edited by: Benton on Nov 9, 2010 1:59 PM

  • How to use multiple aggregate functions in single query

    hi to all
    The output will be giving first_name,last_name,max(salary),min(salary) and the output will be department wise.From employees table in single query
    output will be:
    first_name|last_name|max(salary)|min(salary)

    SELECT first_name||' '||last_name as ename,
           MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
           MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
    FROM   emp
    ORDER BY deptno, sal;Edited by: Ramio on Jan 10, 2012 10:43 PM

  • How to insert multiple records with a single query?

    Hi,
    I've to save a huge number of installments with their other information such as due on blah blah. Now, I want to add the all of these information at once with a single insert query.
    How can I do that?

    Hi
    What is your source data?
    If the source is external to the SQL Server (like a log file, Excel, CSV, JSON, XML, external application...) you can and should insert it all using Bulk Insert operation.
    Pls clarify what is your source data, and if you need more help using Bulk Insert.
    https://www.simple-talk.com/sql/learn-sql-server/bulk-inserts-via-tsql-in-sql-server/
    http://msdn.microsoft.com/en-us/library/ms188365.aspx
    [Personal Site] [Blog] [Facebook]

  • How to calculate the individual sums of multiple columns in a single query

    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    Thanks

    user13667036 wrote:
    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    ThanksLooks like you want a simple group by.
    select
              yr
         ,      mnth
         ,      region
         ,     sum(handled_package)
         ,     sum(expected_missing_package)
         ,     sum(actual_missing_package)
    from test
    group by
         yr, mnth, region
    order by      
         yr, mnth, region;I wouldn't recommend storing your data for year / month in 2 columns like that unless you have a really good reason. I would store it as a date column and add a check constraint to ensure that the date is always the first of the month, then format it out as you wish to the client.
    CREATE TABLE test
         year_month                              date,
        Region                     VARCHAR2(50),
        CITY                       VARCHAR2(50),             
        Handled_Package            NUMBER,       
        Expected_Missing_Package   NUMBER,   
        Actual_Missing_Package     NUMBER
    alter table test add constraint firs_of_month check (year_month = trunc(year_month, 'mm'));
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-12', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
    ERROR at line 1:
    ORA-02290: check constraint (TUBBY.FIRS_OF_MONTH) violated
    Elapsed: 00:00:00.03
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-01', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    1 row created.
    Elapsed: 00:00:00.01
    ME_XE?select
      2        to_char(year_month, 'fmYYYY')    as year
      3     ,  to_char(year_month, 'fmMonth')   as month
      4     ,  Region
      5     ,  CITY
      6     ,  Handled_Package
      7     ,  Expected_Missing_Package
      8     ,  Actual_Missing_Package
      9  from test;
    YEAR         MONTH                REGION                         CITY                    HANDLED_PACKAGE EXPECTED_MISSING_PACKAGE ACTUAL_MISSING_PACKAGE
    2012         November             Western                        San Fransisco                       200                       10                      5
    1 row selected.
    Elapsed: 00:00:00.01
    ME_XE?Then you have nice a nice and easy validation that ensures you data integrity.
    Cheers,

  • Urgent ! How to add multiple JToolBars in a single JFrame

    How to implement multiple JToolBars in a single JFrame
    or what is the concept behind floating toolBars.If anybody can help me ,Thisis very urgent

    If you insist on multiple toolbars, use the following code:
    JToolBar tb1 = new JToolBar();
    //add stuff
    JToolBar tb2 = new JToolBar();
    //add stuff
    //put the toolbars on the top of the window
    JPanel toolbars = new JPanel(new BorderLayout());
    toolbars.add(tb1, BorderLayout.NORTH);
    toolbars.add(tb2, BorderLayout.CENTER);
    getContentPane().add(toolbars, BorderLayout.NORTH);Stephen

  • How to set multiple styles on a single component in flex ?

    Hi ,
    I would like to know how to set multiple styles on a single component in flex.
    Can anyone give me an example as to how to set multiple styles for a single component ?
    Thanks ,
    Regards,
    Ajantha

    Hi tuliptaurus,
    You can setStyleName property for chnaging the external css dynamically by using the setStyle() method ...
    btn.setStyle("styleName","blendButtonSkinOther");
    You can change the external css by using the styleaName property with setStyle method..the line in blue..where blendButtonSkinOther is another css class..
    blendButtonSkin {
        fontFamily: Arial;
        fontSize: 11;
        color: #F1F1F1;
        textRollOverColor: #F1F1F1;
        textSelectedColor: #F1F1F1;
        horizontal-align:center;
        width:150;
        height:30;
        cornerRadius:5;
        upSkin:ClassReference('assets.skins.BlendButtonSkin');
        downSkin:ClassReference('assets.skins.BlendButtonSkin');
        overSkin:ClassReference('assets.skins.BlendButtonSkin');
        disabledSkin:ClassReference('assets.skins.BlendButtonSkin');
        selected-up-skin: ClassReference('assets.skins.BlendButtonSkin');
        selected-down-skin: ClassReference('assets.skins.BlendButtonSkin');
        selected-over-skin: ClassReference('assets.skins.BlendButtonSkin');
    blendButtonSkinOther {
        fontFamily: Arial;
        fontSize: 11;
        color: #F1F1F1;
        textRollOverColor: #F1F1F1;
        textSelectedColor: #F1F1F1;
        horizontal-align:center;
        width:150;
        height:30;
        cornerRadius:5;
        upSkin:ClassReference('assets.skins.BlendButtonSkin');
        downSkin:ClassReference('assets.skins.BlendButtonSkin');
        overSkin:ClassReference('assets.skins.BlendButtonSkin');
        disabledSkin:ClassReference('assets.skins.BlendButtonSkin');
        selected-up-skin: ClassReference('assets.skins.BlendButtonSkin');
        selected-down-skin: ClassReference('assets.skins.BlendButtonSkin');
        selected-over-skin: ClassReference('assets.skins.BlendButtonSkin');
    Thanks,
    Bhasker Chari

  • How to delete multiple data domains with single step ?

    how to delete multiple data domains with single step ?

    You can go to your Endeca-Server domain home e.g.($WEBLOGIC-HOME$/user_projects/domains/endeca_server_domain/EndecaServer/bin)
    run
    [HOST]$ ./endeca-cmd.sh list-dd
    default is enabled.
    GettingStarted is enabled.
    endeca is enabled.
    BikeStoreTest is enabled.
    create a new file from the output just with the domains that you want to delete and then create a loop
    [HOST]$ vi delete-dd.list
    default
    GettingStarted
    endeca
    BikeStoreTest
    [HOST]$ for i in $(cat delete-dd.list); do; ./endeca-cmd.sh delete-dd $i; done
    Remember that this can not be undone, unless you have a backup.

  • Does anyone know how to add multiple pictures to a single frame in iMovie?

    Does anyone know how to add multiple pictures to a single frame in iMovie?

    Maybe you would be better off posting this in the iPhoto or iDVD categories of the forums.
    http://discussions.apple.com/category.jspa?categoryID=143
    http://discussions.apple.com/category.jspa?categoryID=128
    The answer to your question depends on what you ant to do with the DVD.
    Do you want a DVD menu, slide show etc.
    iPhoto will allow you to burn straight to a DVD. Just select the album you want to burn then go to share in the tool bar and select Burn.

  • How to call multiple strus actions froma single jsp

    how to call multiple strus actions froma single jsp, and that actions should be automatically called pls help me
    Thanks in advance

    how to call multiple strus actions froma single jsp, and that actions should be automatically called pls help me
    Thanks in advance

  • How to use multiple tape drive for single filesystem on single client.

    Hello All.
    I want to backup single filesystem with multiple tape drive.
    Incase of Symantec veritas netbackup "NEW_STREAM" for multi-stream backup.
    Backup client has a  single backup filesystem like /data1  directory with 4 LTO6 drives.
    /data1 directory doesn't have a sub-direcotry, just present a files.
    If /data1 directory has a sub-directory like /data1/aaa, /data1/bbb, /data1/ccc , Is it possible to use multiple drives?
    Please anybody answer the questions.
    Thanks advanced.

    See how to use multiple tape drive from single client when I want to backup single filesystem?

  • Multiple databases in a single query

    I need to query multiple databases in a single query.
    e.g.
    Database d1 contains table t1 with column id
    Database d2 contains table t2 with column id
    I need a query like
    SELECT * FROM t1, t2 WHERE t1.id = t2.id;
    is this possible in jdbc? if yes can anyone help with some sample code?
    thanks,
    Ashish Saraf

    It is not possible using the JDBC API to query tables in two or more databases using a single query. The reason is that a JDBC Connection is made to a single data source.
    However, some databases support the idea of federations or linked tables. What you do is inside the database manager link or federate a table that is present in another DBMS. Then, pose a single JDBC query to the one DBMS which will have its own table and links to the external tables.
    Another approach is to use a special JDBC driver with a built-in integration engine that will perform a query across multiple databases. In effect, the system poses separate queries to the different databases and integrates and joins the data together for you automatically on the client-side. That is much easier than doing it yourself in code, but that is also possible for simple queries.
    As part of my research program, we have released a shareware version of the UnityJDBC driver that can query multiple databases using a single SQL query. For more information, see:
    http://www.unityjdbc.com
    http://www.cs.uiowa.edu/~rlawrenc/research/projects.html
    Sincerely,
    Dr. Ramon Lawrence
    Assistant Professor
    Department of Computer Science
    University of Iowa
    [email protected]

  • How to use multiple hierarchies for a single char in single query

    Hi,
    Is there any way that we can use multiple hierarchies for a single char in single query. I tried and it just allows me to select one hierarchy even if I use hierarchy variable.
    I have a requirement where user wants to see information related to a cost center with different cost center groups in different hierarchies (every year has different cost center group hierarchies).
    Suppose I want to see information related to a cost center from year 2001-2004.in these four year cost center may have been associated to different groups depending upon that year hierarchy. How can I do that?
    Thanks
    Jona

    Nope. Now way to do this.
    There is always just one hierarchy assigned to a characteristic. And even if the hierarchy was time dependent, it only reads it for one key date and not according to transaction data.
    Regards,
    Beat

  • How to pass multiple values to a single parameter in BW report URL

    Hi Experts,
    I am new to EP and learning .... i am stuck at one point where we need to pass multiple parameters to a BW report URL, this is the URL that we launch from BSP.... Suppose i have to pass different multiple values to a single parameter, how to do it....
    i m getting many answers to pass parameters to iviews, reports, but not specific to my case.. can u plz help me....
    Thanks in advance
    Priya Rai

    What is the prolem you are facing if you split the single date param as two parameters say startdate and enddate?
    If you pass as single string then you might have to split the same at reciever end.
    Are you trying any thing specific?

  • How to add multiple databases for a single frontend

    We have a project based on distributed databases and we have to workout on .Net framework.I want to know some information of connecting multiple databases for a single frontend and how can we access them.
    If so we have connected 2 databases for a single frontend in future if I want add one more database to it how it will be possible to do it without disturbing the current connectivity.
    Please help me in resolving this problem.
    Thanks......

    hi,
    what do you mean by connecting 2 databases? can you explain further?
    using entityframework you can connect to different databases
    public class CustomerContext : DbContext
    public ReportContext()
    : base("DefaultConnection")
    public DbSet<Customers> Customers { get; set; }
    and your connectionstring (config file)
    <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\\Database\Project.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
    you can add more connection strings on it.
    https://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx
    https://msdn.microsoft.com/en-us/library/ms254978(v=vs.110).aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Maybe you are looking for

  • ITunes 10.3.1 Freezes when I plug in iPhone, various other problems

    I've had loads of problems with iTunes, Windows 7, and my iPhone 4 which I got in february (along with the iPod Touchs I've owned in the past.) Today, my problem is this. Every time I open itunes, it opens fine, and everything is okay. But when I plu

  • Acrobat Forms - Continue text to another sheet

    OK so I am sort of teaching myself to create forms in Acrobat. We have a memo that is a .docx format that I'd like to convert to an Abobe form. The reason being it just seems redundant to edit the document in word - only to then save it as a PDF and

  • Error in posting F-02

    Hi friends, when Im trying to post F-02 Im facing the following error code. system error in routine FI_TAX_CHK_PRICING_DATA  error code 13  functiion builder TAX2. Its a new company code and all the customization is made perfect.

  • Report Problem: HR Pay-roll report in particaular date (period) slab

    Dear Experts,                     I have created a zreport for payroll in which i am also using the logical database called PNP selectioon, but when we execute the report for the output, It always shows the output of one month wise only. But the requ

  • Authorization Objects for Multiple Fields on a Screen

    Hi, I have a requirement to create authorization object on a screen with 20 fields and there are 3 users, each user for eg: User-A has rights to Display and modify a few fields and User-B has rights to diplay and modify a few fields and same is the c