how to write the query to select the rows are in the order
of either 1,3,5,7... or 2,4,6,8,...

Answer Posted / rajesh verma

1> incase of 2,4,6,8,...

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=0
then col1 else 0 end from tab1)

2> in case of 1,3,5,7,....

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=1
then col1 else 0 end from tab1)

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between clustered and non clustered index?

524


What is intellisense?

576


What are the instances when triggers are appropriate?

518


Is ssrs support other database except ms sql server?

96


What are transactions and its controls?

610






is there a column to which a default can't be bound? : Sql server database administration

531


What is the difference between MVC and Teir Architecher? Plz explain with Layyered Programming example...? Thanks

1607


What is a trigger and types of a trigger?

562


What is mean by candidate key?

534


What is executereader?

543


What is the new security features added in sql server 2016? : sql server security

610


What programming language would you use to create embedded functions in ssrs?

122


What is the difference between join and inner join?

533


Can we use where and having clause together?

504


How can you find out which stored procedures are recompiling?

510