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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:40:57

问题


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 it in 1?


回答1:


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



回答2:


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



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/3756928/selecting-rows-where-remainder-modulo-is-1-after-division-by-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!