有两个列 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能实现吗

解决方案 »

  1.   

    这样试试:
    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')
      

  2.   

    -*-try
    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'
      

  3.   

    select 列名=case
                    when BETWEEN '2007-1- 1 ' AND  '2007-12-31' then b
                end
                 from 表名
      

  4.   

    marco08(天道酬勤)  的方法最符合