加法
#加一个常数
SELECT "A" + 5 FROM "add"
SELECT * FROM "add" WHERE "A" + 5 > 10
#两个字段相加。
SELECT "A" + "B" FROM "add"
SELECT * FROM "add" WHERE "A" + "B" >= 10
减法
#减法里带常数。
SELECT 1 - "A" FROM "sub"
SELECT * FROM "sub" WHERE 1 - "A" <= 3
#两个字段做减法。
SELECT "A" - "B" FROM "sub"
SELECT * FROM "sub" WHERE "A" - "B" <= 1
乘法
#乘以一个常数。
SELECT 10 * "A" FROM "mult"
SELECT * FROM "mult" WHERE "A" * 10 >= 20
#两个字段相乘。
SELECT "A" * "B" * "C" FROM "mult"
SELECT * FROM "mult" WHERE "A" * "B" <= 80
#乘法和其他运算符混用。
SELECT 10 * ("A" + "B" + "C") FROM "mult"
SELECT 10 * ("A" - "B" - "C") FROM "mult"
SELECT 10 * ("A" + "B" - "C") FROM "mult"
除法
#除法里带常数。
SELECT 10 / "A" FROM "div"
SELECT * FROM "div" WHERE "A" / 10 <= 2
#两个字段相除。
SELECT "A" / "B" FROM "div"
SELECT * FROM "div" WHERE "A" / "B" >= 10
#除法和其他运算符混用。
SELECT 10 / ("A" + "B" + "C") FROM "mult"
求模
#模一个常数。
SELECT "B" % 2 FROM "modulo"
SELECT "B" FROM "modulo" WHERE "B" % 2 = 0
#两个字段求模。
SELECT "A" % "B" FROM "modulo"
SELECT "A" FROM "modulo" WHERE "A" % "B" = 0
按位与
你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。
SELECT "A" & 255 FROM "bitfields"
SELECT "A" & "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" & 15 > 0
SELECT "A" & "B" FROM "booleans"
SELECT ("A" ^ true) & "B" FROM "booleans"
按位或
你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。
SELECT "A" | 5 FROM "bitfields"
SELECT "A" | "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" | 12 = 12
按位异或
你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。
SELECT "A" ^ 255 FROM "bitfields"
SELECT "A" ^ "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" ^ 6 > 0