Selecting rows where remainder (modulo) is 1 after division by 2?

后端 未结 4 1485
猫巷女王i
猫巷女王i 2020-12-13 06:02

There is a column in options that hold an integer. I want to select the row only if that value % 2 = 1.

I know this can be done in 2 queries but is it possible to do

相关标签:
4条回答
  • 2020-12-13 06:20

    At least some versions of SQL (Oracle, Informix, DB2, ISO Standard) support:

    WHERE MOD(value, 2) = 1
    

    MySQL supports '%' as the modulus operator:

    WHERE value % 2 = 1
    
    0 讨论(0)
  • 2020-12-13 06:21

    MySQL, SQL Server, PostgreSQL, SQLite support using the percent sign as the modulus:

    WHERE column % 2 = 1
    

    For Oracle, you have to use the MOD function:

    WHERE MOD(column, 2) = 1
    
    0 讨论(0)
  • 2020-12-13 06:23

    select * from table where value % 2 = 1 works fine in mysql.

    0 讨论(0)
  • 2020-12-13 06:29

    Note: Disregard this answer, as I must have misunderstood the question.

    select *
      from Table
      where len(ColName) mod 2 = 1
    

    The exact syntax depends on what flavor of SQL you're using.

    0 讨论(0)
提交回复
热议问题