Results 1 to 8 of 8

Thread: even numbers

  1. #1
    Join Date
    Sep 2012
    Posts
    9

    Unanswered: even numbers

    hey i got this assignment for school;
    show all students with an even student_ID, do not use the or, in or and operator.

    i got this far, but only with the or operator;

    select student_ID
    from students
    where student_ID like '%0' or student_ID like '%2' or student_ID like '%4' or student_ID like '%6' or student_ID like '%8'
    note that i may not use the operators named at the top!

    could you help me?

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Select student_id from students where mod(student_id,2) = 0;
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Another option is to use binary arithmetics:
    Code:
    SQL> select empno, ename from emp where bitand(empno, 1) = 1;
    
         EMPNO ENAME
    ---------- ----------
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7839 KING

  4. #4
    Join Date
    Sep 2012
    Posts
    18
    select student_id from table where student_id not in (3,5,7,9,11) ;


    lol

  5. #5
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Huh, what if it is a university with THOUSANDS of students? Do you plan to enumerate ALL even numbers?

    Anyway, you failed to satisfy one of the original conditions: you can not use IN operator (NOT IN included).

  6. #6
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    To use BITAND for even numbers you should use BITAND(empno,1) = 0. I was running tests to see performance differences between MOD and BITAND and BITAND is considerably quicker. I ran a set of queries and have published the results here Oracle – Get even numbers IT Integrated Business Solutions
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  7. #7
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Quote Originally Posted by it-iss.com
    To use BITAND for even numbers you should use BITAND(empno,1) = 0
    LOL, by all means!

    Back to English classes, ASAP!

  8. #8
    Join Date
    Sep 2012
    Posts
    9
    the:
    mod(student_ID,2) = 0
    worked great! thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •