–Now create a table tbemp1 and insert some records in it.
create table tbemp1(empno int, ename varchar(50), eadd varchar(50), esal int, edno int)
–Insert some records in it
insert tbemp1 values(1,’Amit’,'sample address’,12000,10)
insert tbemp1 values(2,’Raj’,'sample address’,14000,20)
insert tbemp1 values(3,’John’,'sample address’,18000,30)
insert tbemp1 values(4,’Rajni’,'sample address’,20000,10)
insert tbemp1 values(5,’Suraj’,'sample address’,18000,20)
insert tbemp1 values(6,’Rohit’,'sample address’,22000,10)
insert tbemp1 values(7,’Bharat’,'sample address’,12000,30)
GO
select * from tbemp1
– ROW_NUMBER() will display records with serial no.
select ROW_NUMBER() over (order by esal) as sr, esal,ename from tbemp1
– partition by It will display serial no. according to edno
select ROW_NUMBER() over (partition by edno order by esal desc) as sr, edno,esal,ename from tbemp1
READ MORE »





Recent Comments