Top ten from each dept
In EmP tabel, empname ,deptno ,sal.In Dept column there are three departments they got 20 employees each ,how to get the top
5 highest sal from each department
You're in the wrong forum (this one is for issues with the SQL Developer tool). You'll get more answers in the SQL And PL/SQL forum...
Have fun,
K.
Similar Messages
-
How to get two top salaries from each department
select st.staff_name,st.dept_code,
st.staff_sal
from staff_master st
where staff_code in ((select staff_code
from staff_master s
where staff_sal=(select max(staff_sal) from staff_master where dept_code=st.dept_code))
union
select staff_code from staff_master st where staff_sal=
(select max(staff_sal) from staff_master where dept_code=st.dept_code and staff_sal < (select max(staff_sal) from staff_master where dept_code=st.dept_code)))
order by st.dept_code;You can use RANK, DENSE_RANK or even ROW_NUMBER based on your need. Below is an example using DENSE_RANK. I have used EMP table available in SCOTT schema.
SQL> select * from emp order by deptno, sal desc;
EMPNO ENAME JOB MGR HIREDATE SAL COM DEPTNO ID
7782 CLARK MANAGER 7839 09-JUN-13 12450 0 10
7839 KING PRESIDENT 17-NOV-13 5000 0 10
7788 SCOTT ANALYST 7566 19-APR-87 13000 0 20
7369 SMITH CLERK 7902 02-APR-13 12975 0 20
7566 JONES MANAGER 7839 02-APR-13 12975 0 20
7876 ADAMS CLERK 7788 23-MAY-87 11101 0 20
7698 BLAKE MANAGER 7839 01-MAY-13 12850 0 30
7499 ALLEN SALESMAN 7698 20-FEB-13 11600 300 30
7844 TURNER SALESMAN 7698 08-SEP-13 11500 0 30
7521 WARD SALESMAN 7698 22-FEB-13 11250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-13 11250 1400 30
11 rows selected.
SQL> select *
2 from (
3 select e.*
4 , dense_rank() over(partition by deptno order by sal desc) emp_rank
5 from emp e
6 )
7 where emp_rank <= 2;
EMPNO ENAME JOB MGR HIREDATE SAL COM DEPTNO ID EMP_RANK
7782 CLARK MANAGER 7839 09-JUN-13 12450 0 10 1
7839 KING PRESIDENT 17-NOV-13 5000 0 10 2
7788 SCOTT ANALYST 7566 19-APR-87 13000 0 20 1
7369 SMITH CLERK 7902 02-APR-13 12975 0 20 2
7566 JONES MANAGER 7839 02-APR-13 12975 0 20 2
7698 BLAKE MANAGER 7839 01-MAY-13 12850 0 30 1
7499 ALLEN SALESMAN 7698 20-FEB-13 11600 300 30 2
7 rows selected.
SQL> -
Need to display average percent of spend for each vendor in top ten
Hi Friends,
I have to design a query where I need to display top ten vendors and for that top ten vendors need to sum the AMT and I have to calculate the average percentage of each vendor in top ten list from the total. Based and the specified range have to create exceptions.
I am able to display top ten vendors. Now the problem is unable to calculate total of top ten vendors and average percentage of each vendor from total. like the below
spend Spend Ratio Spend Percentage
vendor 4 121987 0.299181333 30% 80% is an A
vendor 10 101103 0.247961917 55%
vendor 8 98723 0.242124806 79%
vendor 9 23456 0.05752742 85% 80-95% is a B
vendor 5 12345 0.030276944 88%
vendor 6 10540 0.02585006 90%
vendor 7 9906 0.024295132 93%
vendor 3 9903 0.024287774 95% 95-100% is a C
vendor 2 9899 0.024277964 98%
vendor 1 9874 0.02421665 100%
Total 407736
Please, suggest me to proceed further.
Thank You.
ManjulaHi manjula
In order to get total for any key figure .... for that key figure at the query level in the calculation tab there will be one box like calculate result as there u give sum or average accroding to ur purpose... then it will display the total or average accordingly....
the key figure when used average for result shows average of all record conrtibutions but
In order to display the percentage of each vendor from total u can use
Percentage Share of Result (%CT)
%CT<Operand>
Specifies how high the percentage share is in relation to the result. The result
means the result of aggregation at the next level (interim result).
%CT Incoming Orders specifies the share of incoming order values of each
individual characteristic value (for example of each customer) in relation to
the characteristic's result (for example, customer of a division).
Regards
vamsi -
This has happened more than 38 times so far, and its still not fixed within iTunes store, upgrade or the latest version of software. For an example, I have in the Top Tens, section Country number 28 this week Keith Urban with For You from the Act of Valor movie soundtrack which displays $ 1.29. Now again upon just searching on the iPhone 4s with the app Itunes, with the keywords Act of Valor, top results show on display Action & Adventure Act of Valor Movie and Keith Urban, For You Act of Valor $ 1.29.
Now right below with Albums, Various Artists, Act of Valor I selected it displays 1 For You "Downloaded"
Pretty screwed up if you ask me!!really? no answer in a month? no one can help to resolve with a setting ?
-
I have an imac, intel 2 duo. OS 10.6.8. Suddenly my desktop is showing two thin lines running from top to bottom, each about 2" from either side. How can I get rid ofthem?
That's strange...
Resetting PRAM might help: http://docs.info.apple.com/article.html?artnum=2238
If that doesn't help, I'd recommend contacting AppleCare.
it seem to be lcd problem -
Hi,
I have a table with the following rows:
date product_name product_type quantity_sold
I want to get the best selling products in each category i.e. the Top ten products in each product_type on a particular date.
I am using oracle 8.0.6. So I am not able to use the following:
1. Analytical functions like RANK OVER()
2. An order by in an inner query
Somebody please help me with this
Thanks in advance
RajeshHi,
I tried something like this:
Select * from t where rownum < 11
and product_type = 'X'
order by bidding_price
to get the top 10 products of a particular type 'X'.
I didn't work. Once I created an index on bidding_price, it magically started working fine.
Now I thought the next step would be to do the following
Select * from t where rownum < 11
and product_type = 'X'
union all
Select * from t where rownum < 11
and product_type = 'Y'
so on for all the product types which I would find out through a seperate query.
But unfortunately this doesn't give the corret results.
Anybody has an idea of the internals of this ? What is the exact relation between ROWNUM and Index.
Thanks,
Rajesh -
I just recently installed Firefox for the first time. It seems nice and quick. The version is reported as: "10.0.1".
I wanted to save some text from a web page, so navigated to that page, selected the text, and pressed the Control-C combination to COPY the selected text to the buffer. For example, the text I selected looked something like this:
Harry
Ron
Hermione
Hagrid
Albus
NOTE: Each line of text has a small icon to the left of the text.
It is not reasonable to COPY and PASTE each line individually, as there can be hundreds of lines of data. I recall, however, that
doing a COPY and PASTE on this data into Microsoft's Excel will produce cells which have the icons included in the cell, but unfortunately one cannot can't get rid of them! At least I've never found a way to remove them, but that's another issue. :)
Once I'd done the COPY operation I switched to a Notepad window and did a PASTE operation. To my surprise, the text from each line was duplicated. It looked like this:
Harry Harry
Ron Ron
Hermione Hermione
Hagrid Hagrid
Albus Albus
Thinking that there might be something unusual about the web page I looked at the source, but it appeared "normal" -- that is, as expected.
Note: I have done this operation several times before, and have never seen this occur before.
Note: In the actual data some of the lines have quoted text in them. Curiously there is weird behavior on these lines. In some cases the entire line is shown only once. (These occur at the top of the line, and the quoted text is at the beginning of the name.)
When quoted text appears "later" in the name, in some cases the quoted text is duplicated, and in other cases the quoted text is missing altogether! I have also noticed an error with the quoted text, and so will be reporting that to the web site which generates the HTML.
Note that each line of "text" is "anchor text", so if I click on a name the browser navigates to a page for that name.
I believe that the problem is that the COPY operating in Firefox is not simply copying the visible text, but also the ALT=
Below is a sample of what the source HTML looks like:
<a class="lnk" target="_blank" href="http://details.aspx?id=Harry">
<img width="16" height="16" alt="Harry" class="tb_icon" src="http://.../Harry.gif"/>
<span>Harry</span></a>
<br/>
(Because of the true length of the lines in the source HTML, I have stripped out the actual URL of the site.)
To make sure I wasn't imaging this difference I repeated the process within Internet Explorer. In that browser I did not get duplicated data.Try:
*Extended Copy Menu (fix version): https://addons.mozilla.org/firefox/addon/extended-copy-menu-fix-vers/ -
How to get first emp for each dept?
Hi,
I need to do a query to pick up one employee (the first one based on ename or empno)from each department, but I don't want to use min function (for some reason it didn't work on my real date), rather I like to use something like this: The problem is I can only pick one instead of one for each dept.
select ee.* from
(select * from emp
order by ename
) ee,
emp e
where rownum <2
and e.deptno=ee.deptno
ThanksHow about this (if I understood your question correctly)?
select * from
(select distinct deptno from emp) depts,
(select deptno, min(ename) from emp group by deptno) ees
where ees.deptno = depts.deptno;
Test:
14:10:26 ==> create table emp (deptno number, ename varchar2(50));
Table created.
14:10:27 ==> insert into emp values (10, 'Joe');
1 row created.
14:10:27 ==> insert into emp values (10, 'Mary');
1 row created.
14:10:27 ==> insert into emp values (10, 'Ethel');
1 row created.
14:10:27 ==> insert into emp values (20, 'Luke');
1 row created.
14:10:27 ==> insert into emp values (10, 'Sue');
1 row created.
14:10:27 ==> insert into emp values (20, 'Bob');
1 row created.
14:10:27 ==> insert into emp values (30, 'Randy');
1 row created.
14:10:28 ==> select * from
14:10:35 2 (select distinct deptno from emp) depts,
14:10:35 3 (select deptno, min(ename) from emp group by deptno) ees
14:10:35 4 where ees.deptno = depts.deptno;
DEPTNO DEPTNO MIN(ENAME)
10 10 Ethel
20 20 Bob
30 30 Randy -
My top ten requested features for Flash Catalyst Next
Here is my top ten list of requested features for Flash Catalyst:
10. Rearranging of pages / states in the pages / states panel (also resizing to smaller icons)
9. Menu bar option to Insert Custom / Generic Component. There isn't a way to create a custom component without first adding something to stage and then converting that.
8. Edit component on double click in layers panel
7. Replace existing artwork with library component - for example, when you create a button or text input then you should be able to use that skin in all of the text input instances rather than creating new ones every time you choose convert artwork to component
6. Artboard sized to content - no hardcoded size of the project
5. Import of Flex Components / movieclps
4. Flex Capacitor library integration / support - supports deep linking and navigation through your flash catalyst or flex project without coding - all the work is done
3. Integration and coexistence in native Flex project - no fxpl or zip - flat file structure
2. Container support - VGroup HGroup Skinnable Container - set layout property
1. Component Constraints support - top left bottom right horizontal center vertical center baseline width height 100%Additional features:
• When opening a Illustrator file the option to choose which artboard or layers to import (rather than the whole project).
• Set a default option so that all imported text fields from Illustrator use "Fit Height". Mainly because currently it is cutting off the descent but also bc it allows you to change the text content (globalization) and have the text fit.
• Show intersection lines while dragging. At least vertical center and horizontal center... similar to Flex and Illustrator.
• Add a convert to vector when selecting images.
• In the code view the default directory "components" could be renamed to something like: design, compositions, construction, architecture, form, embodiments, chassis, constitution, frame, representation, manifestation, cast, expression, mold, etc. just not skins. design, chassis, representations, cast, expressions, compositions are my favorites. It would be nice to be able to define this folder path in preferences.
• Use the layer name to name the library components. Otherwise there is a directory with 30 assets named "graphic[n]".
• Command to clean out library of unused symbols. -
The Top Ten things that BB needs to fix now
BB Fans after having my BB Classic for nearly a month, I am disappointed that there are several issues that need to be resolved immediately with OS 10. I have started a Top Ten list of issues and features that need to be addressed immediately. Please chime in as many of you have the same issues or know of some that I haven't discovered yet. Now here are my Top Ten:
1. Unable to a complete Synch with BB Link, according to BB tech support the issue comes from pictures that are attached to a contact or a Linked In account. We didn't have this issue with BB OS7.
2. Unable to attach a contact to a text message, error shows contact acnnot be shared.
3. Unable to attach a contact to an e-mail, error shows contact cannot be shared.
4. BB Protect doesn't back up and restore as it did in OS7.
5. BB Protect doesn't locate, display a message or play a sound when you are roaming on another network as it did in OS7. It will only locate on your home network, but it won't perform the other features as it did in OS7.
6. When you search for an e-mail, it takes over 10 seconds and it replys "no results". Go to web based e-mail account and perform the same search and the e-mail is found in seconds. OS7 did this well.
7. BB tech support needs to get better, but part of the problem is that they don't have solutions for our concerns.
8. You cannot forward part of a conversion, it will only forward the complete conversation.
9. You cannot bcc yourself to enable you to keep a copy of an e-mail.
10. an e-mail icon needs to be seperate from hub as text messages are, because it takes to long to get to e-mails when accessing them from the hub.
Please everyone chime in as we need to develop a list of our Top Ten issues and features that we desire in our BB10 devices. BB should listen to us as many of us are loyal to BB nd want to see BB survive, improve and grow.Hi, rwb007,
A few thoughts ...
8. You cannot forward part of a conversion, it will only forward the complete conversation.
True, however copy and paste works: http://docs.blackberry.com/en/smartphone_users/deliverables/67769/mba1343759181682.jsp
9. You cannot bcc yourself to enable you to keep a copy of an e-mail.
How to do this:
a. Compose a new e-mail.
b. Tap the menu icon (three dots) at the lowest right corner
c Tap Add Bcc:
10. an e-mail icon needs to be seperate from hub as text messages are, because it takes to long to get to e-mails when accessing them from the hub.
Remember, you can always select the e-mail account on the Hub, so only that e-mail account's messages are displayed. That said, I'm with you on this one - would be nice to have the option, at least - to add an icon to the main screen for separate e-mail accounts as we had on the 9900/OS 7, although I can hear folks reminding me that also defeats the purpose of the Hub. The simplified Hub design leaves me tapping a lot on the glass to separate which account's e-mails I wish to review as sometimes I find it confusing that all e-mails are mixed together in one long list.
Kind regards,
OBBG -
SQL Select 1 record from each department
assume emp table
1- i want to retrive 1 employee from each department
2- 2 from each
3- total 20 records 1st employee from 1st dept, 2nd from 2nd, 3rd from 3rd, 4th from 1st , 5th from 2nd and so on
Edited by: Fakhr-e-Alam on Aug 10, 2011 3:20 AMIs this homework? Remember to give OTN Forums full credit when you hand in your assignment.
This is how to do the first one: you shoudl be able to figure out the others from here.
SQL> select e.*
2 from emp e
3 where (empno, 1) in
4 ( select x.empno
5 , row_number() over (partition by x.deptno
6 order by x.hiredate )
7 from emp x )
8 order by e.deptno
9 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 BOEHMER MANAGER 7839 09-JUN-81 2450 10
7369 CLARKE CLERK 7902 17-DEC-80 800 20
7499 VAN WIJK SALESMAN 7698 20-FEB-81 1600 300 30
8101 PSMITH 03-DEC-10 40
8060 VERREYNNE PLUMBER 8061 08-APR-08 4000 50
SQL>In this case, the employees are ordered on the basis of HIREDATE, so the longest serving employees are selected from each department. Other definitions of "first" will require different sorting criteria. You know your own business rules.
Cheers, APC
Edited by: APC on Aug 10, 2011 10:33 AM -
I can get the top ten records with this command.
select amt,rank() over (order by qater desc) as qtr
from table1 where rownum<=10;
Now I want to get the sum(amt) in similar query and it is giving problem. How can I do it?
Thank You.I don't think that query does what you think it does. It's a side effect of the analytic window function implementation that you are relying on there. You should really change that to a subquery. When you do that, getting the sum is more obvious ...
select amt, qtr, sum(amt) over ()
from (
select amt, rank() over (order by qater desc) as qtr
from table1)
where qtr <= 10 -
Trying To Create A Top Ten List Table
Dear iWorks Numbers Experts,
I'm having a heck of a time trying to make a numbers Top Ten Table. Here's what I have so far, and it pretty much works except for one problem.
Data Table:
Col A Col B
Apple 53
Banana 24
Grape 42
Orange 64
Pear 53
Etc Etc
Pretend Top Three List:
1. =Lookup(Large(Col B from data table),1), (Col B from data table), (Col A from data table)
Returns:: Orange
2. =Lookup(Large(Col B from data table),2), (Col B from data table), (Col A from data table)
Returns:: Pear
3. =Lookup(Large(Col B from data table),3), (Col B from data table), (Col A from data table)
Also returns pear instead of apple
So I'm making a top ten list based on the number of votes in one column and the "fruit" in the first column. The problem is if two of the data points have an equal number of votes, the top ten list returns the same fruit for every tied vote, instead of naming all the fruits that have the same number of votes.
How do I change the formula to make a Top Ten list without repeats?slants,
Here's a solution that I don't believe is any better than Yvan's, but since I had started on it and since it represents an alternate approach that is somewhat like your first direction, I'll give it to you.
The Data table contains a hidden Column C with the conventional rank expression, slightly modified to eliminate duplicates: =IF(ISBLANK(B), "", RANK(B, B)+RAND()/1000)
Column C is hidden to avoid inadvertently typing over the equation. The "+RAND()/1000" part of the expression adds a very small random offset to avoid duplicates. The use of this method of avoiding duplicates means that you will not be able to predict which of several tie scores will be presented first, but that's not usually a problem.
The bottom table, "Product ArrangedByRank", is locked to avoid corruption, and can be any length to present however many top items you wish. Here again, I don't believe there is any reason to show the rank column, but I left it visible. Rank in the bottom table puts the Rank data from the top table in numerical order via the LARGE function. In Rank we have: =IF(COUNTA(Data :: A)<ROW(), "", LARGE(INDIRECT("Data :: C$2:C$"&COUNT(Data :: C)+1), COUNT(Data :: C)-ROW()+2))
All that counting business is to avoid errors in the case where the tables are of unequal length and where there are empty rows at the bottom of the top table.
The bottom table Product expression is: =IF(COUNTA(Data :: A)<ROW(), "", LOOKUP(C,Data :: C,Data :: A))
And, the bottom table Quantity expression is: =IF(COUNTA(Data :: A)<ROW(), "", LOOKUP(C,Data :: C,Data :: B))
I hope that this along with Yvan's solution will help you.
Jerry -
Please Help! I need a report: Total Items sold from each Supplier.
Dear experts
I would like to build a Query\Report that will show the TOTAL amount of items sold (in invoices) from each supplier.
This is not possible in the reports section, because it is not your regular Salles per cards\items report.
I want the report to show a sum per line. meaning:
I have totally sold from Supplier:'XYZ' 5,123 items (no matter which ones) at a total of 75,540$
I would like the report to show ALL suppliers , thus the reason i want it to show 1 supplier-per line.
I couldnt figure out how to write this Query and if its even possible to make a 'sum per line' report. (like the ones that you output with default report section).
Personally , I found it really odd that it is not in the default reports option, It is higly common for organization to check Who is its Top supplier (in sales) in order to decied how to continue doing buisness with him.
Could any of you experts assist me in writing this Supplier-Sales-Report?
Thank you in advanced,
D.MedalionHi Medalion,
Have you tried using sales analysis reports. Yyou can view items sold to particular customer in that report too. You need to click on items-->tick individual display and tick group by customers. This would give your desired format. Is there anyrhing else that you are looking for ??
You may also check these to get an idea;
Re: Query for top 5 items/customers
Query for top 5 items
This would require s user id and pass word
https://websmp205.sap-ag.de/~sapidb/011000358700001172792006E
Thanks,
Joseph
Edited by: Joseph Antony on Aug 6, 2010 11:19 AM -
Query to retrieveonly three emplyee details from each department-v 10.2.0.4
Hi all,
Need query to retrieve only 3 employees from each department.
Order can be same as server retrieve.
Eg. If dept 10 has 5 employees, query should return only 3 employee details (emp#, deptno, salary).
If dept 20 has only 1 employee then should return one emp details.
Thanks.with t as (
select e.*,
row_number() over(partition by deptno order by 1) rn
from emp e
select *
from t
where rn <= 3
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO RN
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 1
7839 KING PRESIDENT 17-NOV-81 5000 10 2
7934 MILLER CLERK 7782 23-JAN-82 1300 10 3
7369 SMITH CLERK 7902 17-DEC-80 800 20 1
7876 ADAMS CLERK 7788 23-MAY-87 800 20 2
7902 FORD ANALYST 7566 03-DEC-81 3000 20 3
7499 ALLEN SALESMAN 7698 20-FEB-81 1500 300 30 1
7698 BLAKE MANAGER 7839 01-MAY-81 1500 30 2
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 3
9 rows selected.
SQL> SY.
Maybe you are looking for
-
Hello, I recently made it a project to find and in some cases add my own album artwork for the entire list of music in my iTunes library (I have no life I know). In iTunes every track has a piece of album artwork to accompany it. On my iPod however t
-
F110 is not printing any checks
Hi Gurus FBZ5 and F-58 are printing checks but F110 is not. I am assuming when the first two Tcodes are printing, the config is done good enough. I am just not sure what is stopping F110 from printing. When I check 'Own Jobs' the F110 job is listed
-
Dear All, What is Lot size procedure and how it will affect during MRP run? Please provide some example against explanation.
-
How does artwork get linked to an album?
I had to send the MacBook in for service and backed up my Music folder. I was able to copy it over to my backup machine and while all the songs are there some of the album artwork is missing. There must be some meta file(s) somewhere that has this in
-
Sql instance detected even I uninstalled sql 2008 express
I am using SqlDataSourceEnumerator.Instance.GetDataSources() to find if sql instance is installed in my machine or not. I have installed sql server 2008 in my machine,then uninstalled completely,and it didn't show any error. SqlDataSourceEnumerator.I