SQL 选择id为偶数的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35111002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select Rows with id having even number
提问by solanki kaushik
I am passing a simple query where I am searching for specific rows where OrderID
is an even number
我正在传递一个简单的查询,我在其中搜索特定行,其中OrderID
是偶数
SELECT *
FROM Orders
WHERE mod(OrderID,2) = 0;
Error :
错误 :
Syntax error (missing operator) in query expression 'mod(OrderID,2) = 0'.
查询表达式“mod(OrderID,2) = 0”中的语法错误(缺少运算符)。
回答by Tim Biegeleisen
You are not using Oracle, so you should be using the modulus operator:
您没有使用 Oracle,因此您应该使用模数运算符:
SELECT * FROM Orders where OrderID % 2 = 0;
The MOD()
function exists in Oracle, which is the source of your confusion.
该MOD()
函数存在于 Oracle 中,这是您混淆的根源。
Have a look at this SO questionwhich discusses your problem.
看看这个 SO question,它讨论了你的问题。
回答by dotnet technologies
SELECT * FROM Orders where OrderID % 2 = 0;///this is for even numbers
SELECT * FROM Orders where OrderID % 2 != 0;///this is for odd numbers
回答by mxuanlin
MOD() function exists in both Oracle and MySQL, but not in SQL Server.
MOD() 函数存在于Oracle 和 MySQL 中,但不存在于 SQL Server 中。
In SQL Server, try this:
在 SQL Server 中,试试这个:
SELECT * FROM Orders where OrderID % 2 = 0;
回答by Arun Solomon
Sql Server we can use %
我们可以使用的Sql Server %
select * from orders where ID % 2 = 0;
This can be used in both Mysql and oracle. It is more affection to use mod function that %.
这可以在Mysql和oracle中使用。使用 mod 函数比 %.
select * from orders where mod(ID,2) = 0
回答by prashanth
--This is for oracle
--这是给oracle的
SELECT DISTINCT City FROM Station WHERE MOD(Id,2) = 0 ORDER BY City;
回答by dotnet technologies
SELECT * FROM ( SELECT *, Row_Number()
OVER(ORDER BY country_gid) AS sdfg FROM eka_mst_tcountry ) t
WHERE t.country_gid % 2 = 0