我只需要偶数或奇数项,所以我发现模数运算,这不起作用
SELECT * FROM table ORDER BY id WHERE MOD (num, 2) = 1 ASC;
请帮助我,我是 sql 的菜鸟,因为我没有做太多。
SELECT *
FROM table
WHERE MOD (num, 2) = 1
ORDER BY id ASC;
将返回 num 的所有奇数值。
甚至
where ([num]% 2) = 0
对于奇数
where ([num]% 2) <>0
对于偶数,查询:
SELECT
*
FROM
table_name
WHERE
MOD(NUM, 2) = 0
ORDER BY
ID ASC;
对于奇数,查询:
SELECT
*
FROM
table_name
WHERE
MOD(NUM, 2) != 0
ORDER BY
ID ASC;
SELECT * FROM table WHERE MOD(num, 2) = 1 ORDER BY id ASC;
在根据 where 条件获取 sql server 的最终结果集之后,只有我们可以应用任何排序ASC
和DESC
。