how to show only even or odd rows in sql server 2008?

前端 未结 16 1434
甜味超标
甜味超标 2020-12-05 13:53

i have a table MEN in sql server 2008 that contain 150 rows.

how i can show only the even or only the odd rows ?

thank\'s in advance

16条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 14:43

    Assuming your table has auto-numbered field "RowID" and you want to select only records where RowID is even or odd.

    To show odd:

    Select * from MEN where (RowID % 2) = 1
    

    To show even:

    Select * from MEN where (RowID % 2) = 0
    

提交回复
热议问题