有两个列 a 和 b,都是日期列 如果 列 a 是 1900-1-1 则 select sum(1) from 表 where b BETWEEN '2007-1- 1 ' AND '2007-12-31' 如果 列 b 是 1900-1-1 则 select sum(1) from 表 where a BETWEEN '2007-1- 1 ' AND '2007-12-31'因为两个列不同时 为 1900-1-1,一个sql能实现吗
有两个列 a 和 b,都是日期列 如果 列 a 是 1900-1-1 则 select sum(1) from 表 where b BETWEEN '2007-1- 1 ' AND '2007-12-31' 如果 列 b 是 1900-1-1 则 select sum(1) from 表 where a BETWEEN '2007-1- 1 ' AND '2007-12-31'因为两个列不同时 为 1900-1-1,一个sql能实现吗
select sum(1) from 表 where
(a = '1900-1-1' and b between '2007-1-1' and '2007-12-31')
or
(b = '1900-1-1' and a between '2007-1-1' and '2007-12-31')
select sum(1) from 表
where case when a='1900-1-1' then b when b='1900-1-1' then a end
BETWEEN '2007-1- 1 ' AND '2007-12-31'
when BETWEEN '2007-1- 1 ' AND '2007-12-31' then b
end
from 表名