Analytic function - two answers in one single select
create table atest(eid varchar2(10),ukey varchar2(10),tname varchar2(40));
insert into atest values ('eid1','ukey1','tname1');
insert into atest values ('eid2','ukey1','tname2');
insert into atest values ('eid3','ukey2','tname3');
insert into atest values ('eid4','ukey2','tname3');
insert into atest values ('eid5','ukey3','tname4');
commit;I need one single sql, from which I want to find out 2 things
1. find out those ukey values for which we have multiple eids (ukey1, ukey2 in our example)
2. next, once we identify those ukeys with multiple eids, out of those, find those ukeys which have non unique tnames (in our example ukey1)
I would like to do it using analytic functions, so far tried the following
select eid, ukey,
(case when count(distinct a.eid) over (partition by (a.ukey)) > 1 then
-- do something here, above will give ukey1, ukey2, but how to identify those ukeys with non unique tnames ?
else
end) tsource
from atest a;
user650888 wrote:
can the same be achieved with analytics ? Yes, but why? Anyway:
select ukey
from (
select ukey,
count(distinct eid) over(partition by ukey) eid_cnt,
count(distinct tname) over(partition by ukey) tname_cnt,
row_number() over(partition by ukey order by 1) rn
from atest
where eid_cnt > 1
and tname_cnt > 1
and rn = 1
UKEY
ukey1
SQL> SY.
Similar Messages
-
Select or deselect multiple rows with one single selection event
Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
row1
row2
row3
row4
row5
row6
What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
Hopefully someone can give me a hint.Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
private void addLineToList() {
String a = f_one.getText();
String b = f_two.getText();
if (a.length() == 0) {
Utils.showInformationMessage("Item field is empty.");
f_one.requestFocusInWindow();
return;
if (b.length() == 0) {
Utils.showInformationMessage("Match field is empty.");
f_two.requestFocusInWindow();
return;
model.addElement("item: " + a);
model.addElement("match: " + b);
model.addElement(" ");
int size = model.getSize();
pairList.setSelectedIndex(size - 3);
f_one.setText("");
f_two.setText("");
f_one.requestFocusInWindow();
private void editList() {
if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
Toolkit.getDefaultToolkit().beep();
f_one.requestFocusInWindow();
return;
if (!f_one.getText().equals("")) {
int result = JOptionPane.showConfirmDialog(this,
"The Item field contains text. Replace the text?",
"Flash Card Activity", JOptionPane.YES_NO_OPTION,
OptionPane.INFORMATION_MESSAGE);
if (result == JOptionPane.NO_OPTION) return;
if (!f_two.getText().equals("")) {
int result = JOptionPane.showConfirmDialog(this,
"The Match field contains text. Replace the text?",
"Flash Card Activity", JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (result == JOptionPane.NO_OPTION) return;
String item = "";
String match = "";
int index = pairList.getSelectedIndex();
String choice = model.getElementAt(index).toString();
if (choice.startsWith("item")) {
item = choice;
match = model.getElementAt(index + 1).toString();
model.remove(index);
model.remove(index);
model.remove(index);
else {
item = model.getElementAt(index - 1).toString();
match = choice;
model.remove(index + 1);
model.remove(index);
model.remove(index - 1);
int size = model.getSize();
if (size > 2) {
pairList.setSelectedIndex(size - 2);
f_one.setText(item.substring(6));
f_two.setText(match.substring(7));
f_one.requestFocusInWindow();
} -
How to open two sockets in one single server
May I open two sockets with different listening port numbers in a single server? For each socket, the way to deal with the inputstream and outputstream is different. May the thread be like this:
public class twoSocketServer implements Runnable {
public twoSocketServer() {
try{
SSLServerSocketFactory fact = SSLServerSocketFactory.getInstance(rand, selfPrivateKey, selfCertificate, trustEngine, null);
serverSocket1 = (SSLServerSocket) fact.createServerSocket(ListeningPort1);
serverSocket1.setNeedClientAuth(false);
serverSocket2 = (SSLServerSocket) fact.createServerSocket(ListeningPort2);
serverSocket2.setNeedClientAuth(false);
} catch {...}
public void run()
while(true)
try
SSLSocket socket1 = (SSLSocket) serverSocket1.accept();
new handler1(socket1).start();
SSLSocket socket2 = (SSLSocket) serverSocket2.accept();
new handler2(socket2).start();
} catch {...}
class handler1 extends Thread {...}
class handler2 extends Thread {...}
Is there something wrong with this idea? If yes, how can I correct it? Thanks.try
SSLSocket socket1 = (SSLSocket)
serverSocket1.accept();
new handler1(socket1).start();
SSLSocket socket2 = (SSLSocket)
serverSocket2.accept();
new handler2(socket2).start();
Is there something wrong with this idea? If yes, how
can I correct it? Thanks.You can do it.
In the above code block you are going to need two threads. One for each SocketServer. The accept() method blocks until it recieves a connection. So in your above code it would first wait only for a connection on port 1. Then it would wait only for a connection on port 2. And then start over. That probably isn't what you want. -
Plotting two graphs in one single graph
Hi. This is my first time using control and simulation. I want to plot two graphs within a single graph. It seems that I have to use bundle and build arrays functions but I just do not know how to plot them. The x points and y points of (2) are just defined by a single set of points included in the array defined. The x points and y points of (1) are results of another formula, but both plots would fit in the same location of a single graph. I hope my question is understandable. I attach part of the model that I want to be plotted.
Thank you
Solved!
Go to Solution.
Attachments:
two graphs.JPG 26 KBHi,
You can try something like this. Check the attached VI.
Regards,
Nitzz
(Give Kudos to good Answers and Mark it as a Solution if your problem is Solved)
Attachments:
Untitled 3.vi 39 KB -
How to concatenate two colums into one single column
I need some ideas to concatenate two different columns into one single column using a set of distinct values.
For Example,
Customer Product Number
xyz A 1
xyz B 2
xyz B 1
AAA C 7
AAA A 1
The result should look like this,
Customer Value
xyz A1 B2 B1
AAA C7 A1
How would I group this into once value ?
Thanks in advance ...Tom's discussion of writing your own aggregate routines
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2196162600402
starts off with a link to the 8i alternatives
"see
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:229614022562
for 8i methods (not aggregates)"
Unforutnately, it's a lot more work in 8i.
Justin -
Display two fields in one single cell in a BEx report.
In a BEx 7 query, we need to display 'First name' and 'Last name' in one cell/column called "Name". The 'First name' and 'Last name' are two different info objects in the multiprovider on which the query is built. These are navigational attributes for Char - Employee. The entire flow is in 7.0 version.
Any pointers to how this can be done in the query designer?
Thanks.Hi,
Follow the following steps:
1. Create a Variable and in General Tab Set Processing By As Customer Exit.
2. Now go to CMOD & Write the following code doing some custom changes specific to your requirement:
WHEN "Variable Name"
"Here you can write a code to select the value from Infocube table and Loop it in a work area"
Loop it_tab INTO wa
concatenate S_date s_tstmp into s_val_new separated by space.
l_s_range-low = s_val_new.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
END LOOP
Note: l_s_range is a structure and holds a single line whereas E_T_range stands for internal table and have multiple values . in customer exit (used for variable ) holds the derived value for the variable .
You can go to query and there u can drag this Characteristic on which you created this custom exit variable -
How to make two tables from one single taable
Hi,
i have one table with 100 records and i want to create two tables each with 50 records and with no duplicates. if i will do on bases on empno then i have to check the min and max emp no and then divide them in two tables, is there any automate way of performing this task.
Regards,
AbidaHi,
A rather quick and dirty solution, but definitely works.
I used the HR sample schema (employees table) for this.
hsaprd@706447>create table tab1 as select * from employees where rownum <51;
Table created.
hsaprd@706447>select count(*) from tab1;
COUNT(*)
50
hsaprd@706447>create table tab2 as select * from employees where employee_id nnot in (select employee_id from tab1);
Table created.
hsaprd@706447>select count(*) from tab2;
COUNT(*)
56
hsaprd@706447>
Hope this helps!
-Anand -
Analytic function to retrieve a value one year ago
Hello,
I'm trying to find an analytic function to get a value on another row by looking on a date with Oracle 11gR2.
I have a table with a date_id (truncated date), a flag and a measure. For each date, I have at least one row (sometimes 2), so it is gapless.
I would like to find analytic functions to show for each date :
sum of the measure for that date
sum of the measure one week ago
sum of the measure one year ago
As it is gapless I managed to do it the week doing a group by date in a subquery and using a LAG with offset set to 7 on top of it (see below).
However I'm struggling on how to do that for the data one year ago as we might have leap years. I cannot simply set the offset to 365.
Is it possible to do it with a RANGE BETWEEN window clause? I can't manage to have it working with dates.
Week :LAG with offset 7
SQL Fiddle
or
create table daily_counts
date_id date,
internal_flag number,
measure1 number
insert into daily_counts values ('01-Jan-2013', 0, 8014);
insert into daily_counts values ('01-Jan-2013', 1, 2);
insert into daily_counts values ('02-Jan-2013', 0, 1300);
insert into daily_counts values ('02-Jan-2013', 1, 37);
insert into daily_counts values ('03-Jan-2013', 0, 19);
insert into daily_counts values ('03-Jan-2013', 1, 14);
insert into daily_counts values ('04-Jan-2013', 0, 3);
insert into daily_counts values ('05-Jan-2013', 0, 0);
insert into daily_counts values ('05-Jan-2013', 1, 1);
insert into daily_counts values ('06-Jan-2013', 0, 0);
insert into daily_counts values ('07-Jan-2013', 1, 3);
insert into daily_counts values ('08-Jan-2013', 0, 33);
insert into daily_counts values ('08-Jan-2013', 1, 9);
commit;
select
date_id,
total1,
LAG(total1, 7) OVER(ORDER BY date_id) total_one_week_ago
from
select
date_id,
SUM(measure1) total1
from daily_counts
group by date_id
order by 1;
Year : no idea?
I can't give a gapless example, would be too long but if there is a solution with the date directly :
SQL Fiddle
or add this to the schema above :
insert into daily_counts values ('07-Jan-2012', 0, 11);
insert into daily_counts values ('07-Jan-2012', 1, 1);
insert into daily_counts values ('08-Jan-2012', 1, 4);
Thank you for your help.
FloydHi,
Sorry, I;m not sure I understand the problem.
If you are certain that there is at least 1 row for every day, then you can be sure that the GROUP BY will produce exactly 1 row per day, and you can use LAG (total1, 365) just like you already use LAG (total1, 7).
Are you concerned about leap years? That is, when the day is March 1, 2016, do you want the total_one_year_ago column to reflect March 1, 2015, which was 366 days earlier? If that case, use
date_id - ADD_MONTHS (date_id, -12)
instead of 365.
LAG only works with an exact number, but you can use RANGE BETWEEN with other analytic functions, such as MIN or SUM:
SELECT DISTINCT
date_id
, SUM (measure1) OVER (PARTITION BY date_id) AS total1
, SUM (measure1) OVER ( ORDER BY date_id
RANGE BETWEEN 7 PRECEDING
AND 7 PRECEDING
) AS total1_one_week_ago
, SUM (measure1) OVER ( ORDER BY date_id
RANGE BETWEEN 365 PRECEDING
AND 365 PRECEDING
) AS total1_one_year_ago
FROM daily_counts
ORDER BY date_id
Again, use date arithmetic instead of the hard-coded 365, if that's an issue.
As Hoek said, it really helps to post the exact results you want from the given sample data. You're miles ahead of the people who don't even post the sample data, though.
You're right not to post hundreds of INSERT statements to get a year's data. Here's one way to generate sample data for lots of rows at the same time:
-- Put a 0 into the table for every day in 2012
INSERT INTO daily_counts (date_id, measure1)
SELECT DATE '2011-12-31' + LEVEL
, 0
FROM dual
CONNECT BY LEVEL <= 366 -
Hi,
I have a problem using analytic function: when I execute this query
SELECT TSIUPSITE, TSIUPCEAN , TSIUPDATE, sum(TSIUPCA) TSIUPCA, TSIUPCTVA,TSIUPP4N,TSIUPPIEC,
sum(TSIUPQTE) TSIUPQTE,sum(TSIUPQTEP) TSIUPQTEP, TSIUPMDIU,TSIUPMDar,
sum(TSIUPCRIU) TSIUPCRIU,sum(TSIUPCRAR) TSIUPCRAR, trunc(TSIUPDCRE) TSIUPDCRE ,trunc(TSIUPDMAJ) TSIUPDMAJ ,
TSIUPUTIL,TSIUPTRT,TSIUPNERR,TSIUPMESS,
TSIUPTMVT,TSIUPSMAN, TSIUPMOTIF, sum(TSIUPMHT) TSIUPMHT, 0 vtanfisc,
TSIUPDATEVERIF,TSIUPNSEQ,TSIUPCINV ,count(*) over (partition by TSIUPSITE,TSIUPCEAN,TSIUP_TRT ) CONTA_ARTICOLO
FROM TST_FLIISR_VTEREMART
WHERE 1=1 --TSIUP_TRT = 1
AND TSIUPDATE=to_date('27082012','ddmmyyyy')
and TSIUP_NTRX =172
AND TSIUPSITE = 10025
AND TSIUPCEAN = '8012452018825'
GROUP BY TSIUPSITE, TSIUPCEAN , TSIUPDATE, TSIUPCTVA,TSIUPP4N,TSIUPPIEC,
TSIUPMDIU,TSIUPMDar, trunc(TSIUPDCRE),trunc(TSIUPDMAJ),TSIUPUTIL,TSIUPTRT,TSIUPNERR,TSIUPMESS,
TSIUPTMVT,TSIUPSMAN, TSIUPMOTIF, 0,
TSIUPDATEVERIF,TSIUPNSEQ,TSIUPCINV
ORDER BY TSIUPSITE,TSIUPDATE ;
I have the error ORA-00979: not a GROUP BY expression related to TSIUP_TRT field,infact, if I execute this one
SELECT TSIUPSITE, TSIUPCEAN , TSIUPDATE, sum(TSIUPCA) TSIUPCA, TSIUPCTVA,TSIUPP4N,TSIUPPIEC,
sum(TSIUPQTE) TSIUPQTE,sum(TSIUPQTEP) TSIUPQTEP, TSIUPMDIU,TSIUPMDar,
sum(TSIUPCRIU) TSIUPCRIU,sum(TSIUPCRAR) TSIUPCRAR, trunc(TSIUPDCRE) TSIUPDCRE ,trunc(TSIUPDMAJ) TSIUPDMAJ ,
TSIUPUTIL,TSIUPTRT,TSIUPNERR,TSIUPMESS,
TSIUPTMVT,TSIUPSMAN, TSIUPMOTIF, sum(TSIUPMHT) TSIUPMHT, 0 vtanfisc,
TSIUPDATEVERIF,TSIUPNSEQ,TSIUPCINV ,count(*) over (partition by TSIUPSITE,TSIUPCEAN ) CONTA_ARTICOLO
FROM TST_FLIISR_VTEREMART
WHERE 1=1 --TSIUP_TRT = 1
AND TSIUPDATE=to_date('27082012','ddmmyyyy')
and TSIUP_NTRX =172
AND TSIUPSITE = 10025
AND TSIUPCEAN = '8012452018825'
GROUP BY TSIUPSITE, TSIUPCEAN , TSIUPDATE, TSIUPCTVA,TSIUPP4N,TSIUPPIEC,
TSIUPMDIU,TSIUPMDar, trunc(TSIUPDCRE),trunc(TSIUPDMAJ),TSIUPUTIL,TSIUPTRT,TSIUPNERR,TSIUPMESS,
TSIUPTMVT,TSIUPSMAN, TSIUPMOTIF, 0,
TSIUPDATEVERIF,TSIUPNSEQ,TSIUPCINV
ORDER BY TSIUPSITE,TSIUPDATE ;
I have no problem. Now the difference between TSIUPCEAN ( or TSIUPSITE) and TSIUP_TRT is that TSIUP_TRT is not in Group By clause, but, to be honest, I don't know why I have this problem using using an analitic function.
Thanks for helpHi,
I think you are not using analytic function properly.
Analytical functions will execute for each row. Where as Group BY will execute for groups of data.
See below example for you reference.
Example 1:
-- Below query displays number of employees for each department. Since we have used analytical function for each row you are getting the number of employees based on the department id.
SQL> SELECT e.department_id,count(*) OVER (PARTITION BY e.department_id) cnt_analytic
2 FROM employees e
3 WHERE e.department_id IN (10,20,30);
DEPARTMENT_ID CNT_ANALYTIC
10 1
20 2
20 2
30 6
30 6
30 6
30 6
30 6
30 6
9 rows selected.
Example 2:
-- Since I have used GROUP BY clause I'm getting only single row for each department.
SQL> SELECT e.department_id, count(*) cnt_group
2 FROM employees e
3 WHERE e.department_id IN (10,20,30)
4 GROUP BY e.department_id;
DEPARTMENT_ID CNT_GROUP
10 1
20 2
30 6Finally, what I'm trying to explain you is - If you use Analytical function with GROUP BY clause, the query will not give the menaing ful result set.
See below
SQL> SELECT e.department_id,count(*) OVER (PARTITION BY e.department_id) cnt_analytic, count(*) cnt_grp
2 FROM employees e
3 WHERE e.department_id IN (10,20,30)
4 GROUP BY e.department_id;
DEPARTMENT_ID CNT_ANALYTIC CNT_GRP
10 1 1
20 1 2
30 1 6 -
Analytic function and aggregate function
What are analytic function and aggregate function. What is difference between them?
hi,
Analytic Functions :----------
Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.
Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.
Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.
Aggregate Functions :----------
Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.
If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view. You use aggregate functions in the HAVING clause to eliminate groups from the output based on the results of the aggregate functions, rather than on the values of the individual rows of the queried table or view.
let me know if you are feeling any problem in understanding.
thanks.
Edited by: varun4dba on Jan 27, 2011 3:32 PM -
Merging two records in a single record for the same matnr,werks and bwart.
Hi I have a requirement to merge two records into one single record using the quantity field from MSEG table.
I am selecting two records from the table MSEG. Now for these two records i have to add the quantity values into one variable.
Then there should be only one record for the same matnr,werks,bwart.
Any suggestion would be appreciated.
Regards,
Amithi,
You can COLLECT statement only if all non key fields are numeric.
This statement Adds all such fields and give us a single record.
Regards
Sumit Agarwal -
I use the same List to populate Lookups, one single select and one multi-select.
The multi select is for selected depts that are participating in a project.
Only one dept will be the respondering dept, this is the single select.
The respondering dept must always be part of the depts participating.
So if we pick the respondering dept, it becomes the first selection of the participating depts lookup.
I'd like this to be done by SPServices.
Its not really cascading selects because we don't limit the possible selections in the multi-select...we want them all available.
thx for your helpHi,
According to your post, my understanding is that you wanted to set the first selection of the participating depts lookup.
First, you need to get the single select column value.
Then you need to sort the the multi-select dropdown list.
When you click the dropdown icon, a HTML Table will be appeared.
You can use JQuery to sort the Table.
More information:
https://sites.google.com/site/rogueveggiedevelopment/project-updates/orderingitemsinalookupformfield
http://www.granneman.com/webdev/coding/css/sorting-tables/
http://blog.niklasottosson.com/?p=1914
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
How to use aggregate functions into Analytical functions
Can we use aggregate functions into analytical functions?
Please provide one example.
Smiles.HI Learner6
for information:
Aggregate Functions
Analytic Functions
for practic:
ORACLE-BASE - Analytic Functions
Thank you -
To use "analytic function" at "recursive with clause"
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2077142
The recursive member cannot contain any of the following elements:
・An aggregate function. However, analytic functions are permitted in the select list.
OK I will use analytic function at The recursive member :-)
SQL> select * from v$version;
BANNER
Oracle Database 11g Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> with rec(Val,TotalRecCnt) as(
2 select 1,1 from dual
3 union all
4 select Val+1,count(*) over()
5 from rec
6 where Val+1 <= 5)
7 select * from rec;
select * from rec
ERROR at line 7:
ORA-32486: unsupported operation in recursive branch of recursive WITH clauseWhy ORA-32486 happen ?:|Hi Aketi,
It works in 11.2.0.2, so it is probably a bug:
select * from v$version
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
with rec(Val,TotalRecCnt) as(
select 1,1 from dual
union all
select Val+1,count(*) over()
from rec
where Val+1 <= 5)
select * from rec
VAL TOTALRECCNT
1 1
2 1
3 1
4 1
5 1 Regards,
Bob -
Analytic function for grouping?
Hello @all
10gR2
Is it possible to use an analytic function for grouping following (example-)query:
SELECT job, ename, sal,
ROW_NUMBER() OVER(PARTITION BY job ORDER BY empno) AS no,
RANK() OVER(PARTITION BY job ORDER BY NULL) AS JobNo
FROM emp;The output is following:
JOB ENAME SAL NO JOBNO
ANALYST SCOTT 3000 1 1
ANALYST FORD 3000 2 1
CLERK SMITH 818 1 1
CLERK ADAMS 1100 2 1
CLERK JAMES 950 3 1
CLERK MILLER 1300 4 1
MANAGER Müller 1000 1 1
MANAGER JONES 2975 2 1
....The JobNo should increase group by job and ename; my desired output should be looking like...:
JOB ENAME SAL NO JOBNO
ANALYST SCOTT 3000 1 1
ANALYST FORD 3000 2 1
CLERK SMITH 818 1 2
CLERK ADAMS 1100 2 2
CLERK JAMES 950 3 2
CLERK MILLER 1300 4 2
MANAGER Müller 1000 1 3
MANAGER JONES 2975 2 3
MANAGER BLAKE 2850 3 3
MANAGER CLARK 2450 4 3
PRESIDENT KING 5000 1 4
SALESMAN ALLEN 1600 1 5
SALESMAN WARD 1250 2 5
SALESMAN MARTIN 1250 3 5
SALESMAN TURNER 1500 4 5How can I achieve this?This, perhaps?
with emp as (select 1 empno, 'ANALYST' job, 'SCOTT' ename, 3000 sal from dual union all
select 2 empno, 'ANALYST' job, 'FORD' ename, 3000 sal from dual union all
select 3 empno, 'CLERK' job, 'SMITH' ename, 818 sal from dual union all
select 4 empno, 'CLERK' job, 'ADAMS' ename, 1100 sal from dual union all
select 5 empno, 'CLERK' job, 'JAMES' ename, 950 sal from dual union all
select 6 empno, 'CLERK' job, 'MILLER' ename, 1300 sal from dual union all
select 7 empno, 'MANAGER' job, 'Müller' ename, 1000 sal from dual union all
select 8 empno, 'MANAGER' job, 'JONES' ename, 2975 sal from dual union all
select 9 empno, 'MANAGER' job, 'BLAKE' ename, 2850 sal from dual union all
select 10 empno, 'MANAGER' job, 'CLARK' ename, 2450 sal from dual union all
select 11 empno, 'PRESIDENT' job, 'KING' ename, 5000 sal from dual union all
select 12 empno, 'SALESMAN' job, 'ALLEN' ename, 1600 sal from dual union all
select 13 empno, 'SALESMAN' job, 'WARD' ename, 1250 sal from dual union all
select 14 empno, 'SALESMAN' job, 'MARTIN' ename, 1250 sal from dual union all
select 15 empno, 'SALESMAN' job, 'TURNER' ename, 1500 sal from dual)
select job, ename, sal,
row_number() over(partition by job order by empno) no,
dense_rank() over(order by job) jobno
from emp
JOB ENAME SAL NO JOBNO
ANALYST SCOTT 3000 1 1
ANALYST FORD 3000 2 1
CLERK SMITH 818 1 2
CLERK ADAMS 1100 2 2
CLERK JAMES 950 3 2
CLERK MILLER 1300 4 2
MANAGER Müller 1000 1 3
MANAGER JONES 2975 2 3
MANAGER BLAKE 2850 3 3
MANAGER CLARK 2450 4 3
PRESIDENT KING 5000 1 4
SALESMAN ALLEN 1600 1 5
SALESMAN WARD 1250 2 5
SALESMAN MARTIN 1250 3 5
SALESMAN TURNER 1500 4 5
Maybe you are looking for
-
Preview keeps crashing after installing Mavericks - can't fix it
Hi My first time writing here, so excuse me if I posted this in the wrong section. Preview has been crashing since I upgraded to Mavericks and it seems that I can't find solution for this. I looked over this forum too for similar problems but none of
-
Ram for Asus P9X79 WS & i7 3030k G.Skill responds!
Many of us have had difficulty finding high density ram kits that would be compatible with our planed systems. I have included below my correspondence with the G.Skill Tech Support Team in hopes that it will shed some light on this issue: Dear Sir:
-
Sales order comes in 1 plant and get dispatch in other plant
Hi Guru's we've a scenario where we've one company and 2 plants located in 2 diffrnt states, here we r working on MTO scenario, where lets say we hv 2 plants name 101 n 102. sales order comes for FG in 101 plant it triggers the initial production n r
-
2 questions from new mac owner
Hello all, I've found some good information on these forums and there seems to be a good community here, I'm glad I finally bought a mac. I have two questions: 1- When I copied many digital photographs from dvd's to my hard drive, all of the director
-
Please note: This question specifically refers to Photoshop CS (8.0) for Windows, not CS2 or CS3. Which Photoshop versions qualified for an upgrade to CS? I am talking about the steep upgrade discount, not the shallow one which applied to upgrading t