查询以显示奇数或偶数值

时间:2014-03-25 13:51:23

标签: sql sql-server

我有仓库位置,我想查询并只返回奇数或偶数位置。 我的表看起来像这样:



LOCN  AISLE BAY LVL POSN
F0201A1 F02 1   A   1
F0203A2 F02 3   A   2
F0204A3 F02 4   A   3
F0205B1 F02 5   B   1
F0206B2 F02 6   B   2
F0207B3 F02 7   B   3
F0208C1 F02 8   C   1
F0209C2 F02 9   C   2
F0209C3 F02 9   C   3

3 个答案:

答案 0 :(得分:1)

已编辑以匹配字段名称

SELECT * FROM table WHERE BAY % 2 = 0;

返回偶数号码。

SELECT * FROM table WHERE BAY % 2 = 1;

返回奇数编号的海湾。

答案 1 :(得分:0)

你的问题不是很干净。 购买我假设您有包含整数(街道数量)

的数字的列

使用模数。

像这样:

SELECT number FROM locations WHERE number % 2 = 1

答案 2 :(得分:0)

想出来:

SELECT locn_brcd FROM locn_hdr WHERE locn_brcd BETWEEN 'F0654' AND 'F0679' and  lvl in ('D', 'E', 'F')  and posn in ('1', '2') and mod(bay,2) = 0;

SELECT locn_brcd FROM locn_hdr WHERE locn_brcd BETWEEN 'F0569' AND 'F0580' and  lvl in ('D', 'E', 'F') and mod(bay,2) = 1