Jump to content

Recommended Posts

Hello guys,

 

need help regarding SQL and agregat function, here's the code:

 

SQL>

select department_id, sum(salary) place_total from employees
where department_id is not null group by department_id;

 

 

outputs:

DEPARTMENT_ID PLACE_TOTAL
------------- -----------
           90       58000
           20       19000
          110       20300
           50       17500
           80       30100
           60       19200
           10        4400

 

 

Now, how to edit the current sql statement to output department_id, and max(place_total), so the output result is:

DEPARTMENT_ID PLACE_TOTAL
------------- -----------
           90       58000

 

 

 

Anyone have an idea ?

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/281129-need-help-with-sql-agregat-function/
Share on other sites

No, unfortunately this doesn't do the trick, I'm in Oracle environment,

 

but this syntax also don't do the trick, which is the sam as you mentioned but in oralce syntax:

 

select * from  
(select department_id, sum(salary) place_total from employees
where department_id is not null group by department_id) tmp1 where rownum <= 1 order by place_total desc;

 

, it outputs lowest, no meter if I se ASC or DESC in order by.

Not sure if I clearly explained. Let me try again.

 

"ORDER BY place_total DESC LIMIT 1" in Oracle should be replaced with "rownum <= 1 order by place_total desc;".

 

Al thought, I have done this, still I'm not getting correct result. It just outputs the 1st result which gets from schema by given query , which is the lowest id with the lowest salary. (tried with ASC/DESC also).

 

How do I get the ID and salary or record with the greatest salary ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.