使用多个DATE BETWEEN对选择进行分类

时间:2012-12-12 12:31:01

标签: mysql sql

我的标题问题,所以 如果我有:

SELECT * FROM tbl WHERE date BETWEEN "date[0][start]"
AND "date[0][end]" OR date BETWEEN "date[1][start]" AND "date[1][end]"

我能以某种方式将设备中的结果与where子句

分开

1 个答案:

答案 0 :(得分:1)

每个条件的计算结果为FALSE(0)或TRUE(1)。可以选择表达式的结果作为值,甚至可以按以下值对结果进行排序:

SELECT
    col1, col2, ..., coln,
    date BETWEEN "date[0][start]" AND "date[0][end]" AS first,
    date BETWEEN "date[1][start]" AND "date[1][end]" AS second
FROM tbl
WHERE date BETWEEN "date[0][start]" AND "date[0][end]"
OR date BETWEEN "date[1][start]" AND "date[1][end]"
ORDER BY first