how do we find every fifth record in a table

Answer Posted / saravanan p

If we consider employee2 table having 16 records like

Name Salary
Ajith 10000
Arithas 2000
Balaji 20000
Gamesh 20000
Jith 23000
keerthy 14000
boopathy 21000
moorthy 12000
Muthu Krishnan 30000
Muthu Kumar 80000
naveen 10200
neerthy 40000
Raja 12000
Ramesh 12000
sangeeth 1100
Vairam 23000


With Temp as
(
select row_number() over(order by [name]) as 'rno',
[name] from employee2
)
select [name],salary from Temp
where rno%5 = 0


The result..

Name Salary
Jith 40000
Muthu Kumar 15000
sangeeth 50000

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the default system databases in sql server 2000?

536


Why do we use sql limitations? Which constraints can we use while making a database in sql?

559


Why truncate is ddl?

606


What is the difference between stored procedure and user defined functions?

622


What is forward - only cursors / read only cursor?

522






How to assign new column names in a view?

507


Explain transaction server distributed transaction?

501


Which command is used for user defined error messages?

560


What is the difference between ddl and dml?

568


What is named query? : sql server analysis services, ssas

515


You have several tables, and they are joined together for querying. The tables contain both clustered indexes and non clustered indexes to optimize performance, how should you distribute the tables and their indexes onto different file groups?

553


What are the differences between clustered and non-clustered index?

534


What are pages and extents? : SQL Server Architecture

556


How column data types are determined in a view?

534


what is a check constraint?

638