所以我试过了:
SELECT * FROM `salarystaff` WHERE MONTH(date)=DATEADD(m, -1, getdate())
输出 我想显示上个月的所有数据
答案 0 :(得分:1)
按如下方式更改您的查询:
SELECT * FROM `salarystaff` WHERE MONTH(date_column)=MONTH(CURRENT_DATE - INTERVAL 1 MONTH);
答案 1 :(得分:0)
这是解决方案
SELECT * FROM table_name
WHERE MONTH(date_created) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
答案 2 :(得分:0)
Beginning of current month : DATEADD(month, datediff(month, 0, getdate()), 0)
Beginning of last month : DATEADD(month, datediff(month, 0, getdate())-1, 0)
Your sql will be:
SELECT * FROM XXXX
WHERE date>= DATEADD(month, datediff(month, 0, getdate())-1, 0)
and date< DATEADD(month, datediff(month, 0, getdate()), 0)
此链接可以帮助您 How to get the last month data and month to date data