表里数据如下
id time count
1 2012-12-1 42
2 2012-12-2 112
3 2012-12-4 57
4 2012-12-5 124
5 2012-12-8 241
假设这是基础表,现在要求按天统计2012年12月份的count
想要的结果是:
time count
2012-12-1 42
2012-12-2 112
2012-12-3 0
2012-12-4 57
2012-12-5 124
2012-12-6 0
2012-12-7 0
2012-12-8 241
........
2012-12-31 0
mysql函数应该怎么写?
如果可以的话最好把相同情况下按月统计、按年统计也写一下。
除了新建一张主表存放时间之外,还有什么什么方法
两种解决方法:
1.直接写SQL语句查询,利用MySQL的date_format函数:`日月年:select * from tableName where date_format(fieldName,"%Y-%m-%d")=curdate();`
2.数据查出来在程序中做筛选
PS:date_format的用法可以自己查查看,附图