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

前端 未结 16 1509
甜味超标
甜味超标 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 15:00

    Here’s a simple and straightforward answer to your question, (I think). I am using the TSQL2012 sample database and I am returning only even or odd rows based on “employeeID” in the “HR.Employees” table.

    USE TSQL2012;
    GO
    

    Return only Even numbers of the employeeID:

    SELECT *
    FROM HR.Employees
    WHERE (empid % 2) = 0;
    GO
    

    Return only Odd numbers of the employeeID:

    SELECT *
    FROM HR.Employees
    WHERE (empid % 2) = 1;
    GO
    

    Hopefully, that’s the answer you were looking for.

提交回复
热议问题