第一列有YY(年),第二列有MMDD(月,日)

时间:2014-06-09 18:20:55

标签: sql db2

我试图根据两列提取数据,第一列有YY(年)数据,第二列有MMDD(月,日)。

我将如何编写我的sql语句以从12月13日到日期提取数据。

1 个答案:

答案 0 :(得分:0)

select *
    from table1
    where (
           (yy='13' and substring(mmdd, 1, 2) = '12') or 

           (
           yy>'13' and yy < cast(year(CURDATE() as varchar) 
           ) or

           (
           yy>'13' and yy = cast(year(CURDATE() as varchar) and  substring(mmdd, 1, 2) < cast(month(CURDATE() as varchar) 
           ) or

           (
           yy>'13' and yy = cast(year(CURDATE() as varchar) and  substring(mmdd, 1, 2) = cast(month(CURDATE() as varchar) and  substring(mmdd, 3, 4) <= cast(day(CURDATE() as varchar) 
           )
          )