需要SQL逻辑
示例
Sys date April 15th - April 1 to April 15th date values needs to be fetch.
Sys date May 2nd - April 15th to May 2nd date values needs to be fetch.
请建议
答案 0 :(得分:0)
因此,作为一般方法,您需要一个函数来返回月中的日期编号,并且每个函数返回两个case语句作为边界返回特定日期。日期算术用于将系统日期转换为所需的上限和下限,因此在Oracle上,您将使用Trunc(sysdate,'mm')和add_months(...,n)并将整数添加为整数。
日期功能在这里:http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions001.htm
无法帮助您使用MySQL功能 - 毫无疑问,它们已在某处记录。
你最终会......
date_col > case <function on sysdate>
when < 15 then <function for lower bound case 1>
when < 15 then <function for lower bound case 2>
end and
date_col < case <function on sysdate>
when < 15 then <function for upper bound case 1>
when < 15 then <function for upper bound case 2>
end and
答案 1 :(得分:0)
我建议使用DAYOFWEEK()和MONTH()函数来确定查询的开始和结束日期。
SET @day = DAYOFMONTH(<date entered>)
SET @month = MONTH(<date entered>)
IF @month > MONTH(NOW()) AND @day = 2 THEN
SET @start_date = DATE_SUB(<date entered>, INTERVAL 1 MONTH) + INTERVAL 13 DAY
SET @end_date = <date entered>
ELSEIF @month = MONTH(NOW()) AND @day = 15 THEN
SET @start_date = DATE_SUB(<date entered>, INTERVAL 14 DAY)
SET @end_date = <date entered>
END IF;
SELECT * FROM myTable WHERE myDate BETWEEN @start_date AND @end_date