mysql中的指定月份上个月数据
我想显示指定月份的数据和年份上个月的数据 示例:我的输入是2014年12月,我想显示2014年11月的数据 我有表userBalance和字段:mysql中的指定月份上个月数据,mysql,Mysql,我想显示指定月份的数据和年份上个月的数据 示例:我的输入是2014年12月,我想显示2014年11月的数据 我有表userBalance和字段: mappingid varchar(200); username varchar(200); createddate datetime; openingBalance varchar(200); 我有一个程序来获取上个月的“monthint”和“yearint”期初余额: 我试过: select * from userBalance wher
mappingid varchar(200);
username varchar(200);
createddate datetime;
openingBalance varchar(200);
我有一个程序来获取上个月的“monthint”和“yearint”期初余额:
我试过:
select *
from userBalance where userBalance.username='e00b6542-b5c6-11e4-aee9-00016c0fd125' and
month(userBalance .createddate) =(select DATE_SUB(month(userBalance .createddate),INTERVAL 1 MONTH));
但通过指定month()
,无法从表中获取数据
请帮帮我
SELECT * from tbl_usertask
where userBalance.username='e00b6542-b5c6-11e4-aee9-00016c0fd125' and
month( DATE_SUB(userBalance.createddate,INTERVAL -1 MONTH))=monthint and
year( DATE_SUB(userBalance.createddate,INTERVAL -1 MONTH))=yearint;
?使用此查询,我获得了预期的输出。谢谢您的数据是如何存储在数据库中的。列的数据类型是什么。提供表结构和一些示例数据。
SELECT * from tbl_usertask
where userBalance.username='e00b6542-b5c6-11e4-aee9-00016c0fd125' and
month( DATE_SUB(userBalance.createddate,INTERVAL -1 MONTH))=monthint and
year( DATE_SUB(userBalance.createddate,INTERVAL -1 MONTH))=yearint;