此SQL语句在去年正常运行,选择当前月份大于Subquery
Max
个月匹配ciient_id
的数据。现在,Subquery
返回Max
月份是去年12,是否比较今年的当前月份是1.这就是为什么SQL语句返回0记录。
我必须找出client_id
,即当前月份Subquery
中不存在的SELECT c.id, p.pkg_rate AS amount
FROM tbl_client AS c
INNER JOIN tbl_package AS p ON c.pkg_id = p.id
WHERE c.status=1 AND
Month(Date())>(SELECT Month(Max([due_month])) FROM tbl_payment_due WHERE
c.id=client_id);
。要么我可以与日期进行比较。请帮我离开这里。
/ROOT/Customer/
-- LastName
-- FirstName
-- SSN
/ROOT/Customer/Order
-- OrderID
/Root/Customer/Order/Details
-- Item ID
-- Item QTY
答案 0 :(得分:1)
一种方法是首先将日期格式化为字符串。
Format(Date(),"yyyymm") > (SELECT Format(Max([due_month]),"yyyymm") FROM tbl_payment_due WHERE c.id=client_id)
第二个选项是在WHERE
子句中添加年份检查(注意:我的括号可能稍微偏离)。
(Year(Now()) > (SELECT Year(Max([due_month])) FROM tbl_payment_due WHERE c.id=client_id)) OR
((Year(Now()) = (SELECT Year(Max([due_month])) FROM tbl_payment_due WHERE c.id=client_id)) AND (Month(Date())>(SELECT Month(Max([due_month])) FROM tbl_payment_due WHERE c.id=client_id)))