这是sql语句只给出一个值
SELECT count(pn1) FROM pledges
WHERE date1
BETWEEN '2011-05-05' AND '2011-06-06'
我想在同一列或同一表中的不同列中多次使用“之间”
例如我想在date1中多次使用它,或者我想将它用于date1和date2,具有不同的范围
注意:我正在使用java DB Derpy(JDBC-Derby)
答案 0 :(得分:6)
同一列不止一次:
SELECT count(pn1)
FROM pledges
WHERE date1 BETWEEN '2011-05-05' AND '2011-06-06'
OR date1 BETWEEN '2011-07-05' AND '2011-08-06'
两个不同的栏目:
SELECT count(pn1)
FROM pledges
WHERE date1 BETWEEN '2011-05-05' AND '2011-06-06'
AND date2 BETWEEN '2011-05-05' AND '2011-06-06'
编辑:根据评论,或许您正在寻找类似的内容?
SELECT SUM(CASE WHEN date1 BETWEEN '2011-05-05' AND '2011-06-06' THEN 1 ELSE 0) END AS Count1,
SUM(CASE WHEN date1 BETWEEN '2011-07-05' AND '2011-08-06' THEN 1 ELSE 0) END AS Count2
FROM pledges
WHERE date1 BETWEEN '2011-05-05' AND '2011-06-06'
OR date1 BETWEEN '2011-07-05' AND '2011-08-06'