I’m actually running oracle, but when I copied my example into sqlfiddle, it wouldnt run if I chose oracle instead of mysql, perhaps the fiddle version of oracle is different from mine.
http://www.sqlfiddle.com/#!2/44933/1
CREATE TABLE Positiontest(
ID VARCHAR(20),
code CHAR(06),
registrationdate DATE,
PRIMARY KEY(ID,code)
);
INSERT INTO Positiontest VALUES('01','COM002','2012-12-11');
INSERT INTO Positiontest VALUES('02','COM002','2012-12-12');
INSERT INTO Positiontest VALUES('01','COM003','2012-12-11');
This gives me positiontest table:
ID CODE REGISTRATIONDATE
01 COM002 2012-12-11
02 COM002 2012-12-12
01 COM003 2012-12-11
I want to create a view that looks like:
ID CODE POSITION
01 COM002 1
02 COM002 2
01 COM003 1
The order is not important, aslong as there
is one uniqe position for each code.
You want the
row_number()function: