Select the Even and Odd records

How to select the Even and Odd records in SQL server and in Oracle without using ROWNUM,ROWID

Showing Answers 1 - 3 of 3 Answers

ETL Dev

  • Jul 25th, 2015
 

If the values have any ID values the usign mod function we can provide the details
mod(id,2)=0 will be even and mod(id,2)=1 will be odd

  Was this answer useful?  Yes

MUKUL MALIK

  • Aug 22nd, 2016
 

SELECT customerid,case when customerID %2=0 then even
when customerID %2 < > 0 then odd end as result from customers

  Was this answer useful?  Yes

Sirisha d

  • Jan 30th, 2017
 

Code
  1. TO SELCT EVEN RECORDS IN ORACLE :

  2. -----------------------------------------------

  3. SELECT CUSTOMERID

  4. FROM

  5. (SELECT

  6. CUSTIMERID,

  7. CASE WHEN MOD(CUSTOMERID,2)=0 THEN EVEN WHEN (CUSTOMERID/2)=1 THEN ODD ELSE OTHER END AS EVEN_ODD

  8. FROM

  9. CUSTOMERS)

  10. WHERE EVEN_ODD=EVEN

  11.  

  12. TO SELCT ODD RECORDS IN ORACLE :

  13. -----------------------------------------------

  14. SELECT CUSTOMERID

  15. FROM

  16. (SELECT

  17. CUSTIMERID,

  18. CASE WHEN MOD(CUSTOMERID,2)=0 THEN EVEN WHEN (CUSTOMERID/2)=1 THEN ODD ELSE OTHER END AS EVEN_ODD

  19. FROM

  20. CUSTOMERS)

  21. WHERE EVEN_ODD=ODD

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions