SQLite 按照日期分组
来源:互联网 发布:怪物猎人x数据库 编辑:程序博客网 时间:2024/06/06 06:45
使用这个format ('%Y-%m-%d')来查询对应的年月日的分组
查询2015年的所有数据
select * from mytable where strftime('%Y', datatime) = '2015'
查询2015年9月的所有数据(注意格式一定要是yyyy-MM, 不能使用2015-9)
select * from mytable where strftime('%Y-%m', datatime) = '2015-09'
查询2015年9月23号的所有数据同理推断为
select * from mytable where strftime('%Y-%m-%d', datatime) = '2015-09-23'
以下这个语句是:取出月份,并加上2个月的查询结果,满足代码中循环的需要
select * from mytable where strftime('%m', datatime, '+2 months') = '12'
以下的数据就可以满足按照年来进行分组查询
SELECT count(*) from mytable GROUP BY strftime('%Y', datatime)
以下可以实现查询数据库表中有几个不同的年份
SELECT DISTINCT strftime('%Y', TimeField) as year from YourTable
- strftime时间字串格式化
- %d day of month: 00
- %f fractional seconds: SS.SSS
- %H hour: 00-24
- %j day of year: 001-366
- %J Julian day number
- %m month: 01-12
- %M minute: 00-59
- %s seconds since 1970-01-01
- %S seconds: 00-59
- %w day of week 0-6 with Sunday==0
- %W week of year: 00-53
- %Y year: 0000-9999
- %%%
- 以下结果是等价的
- date(...) <---> strftime('%Y-%m-%d', ...)
- time(...) <---> strftime('%H:%M:%S', ...)
- datetime(...) <---> strftime('%Y-%m-%d %H:%M:%S', ...)
- julianday(...) <---> strftime('%J', ...)
- 再看看修饰符:
- 1. NNN days --加或减N天
- 2. NNN hours ----加或减N小时
- 3. NNN minutes --加或减N分钟
- 4. NNN.NNNN seconds ----加或减N秒
- 5. NNN months --加或减N月
- 6. NNN years --加或减N年
- 7. start of month --一月的开始的时间
- 8. start of year --一年开始的时间
- 9. start of day --一天开始的时间
- 10. weekday N --查看本周礼拜N是那天, 1,2,3,4,5,6,0分别代表礼拜一到礼拜天,礼拜天
0 0
- SQLite 按照日期分组
- 本地搜索功能以及整理数据按照日期来分组
- MySql 使用GROUP BY 按照日期分组统计
- 按照年月日星期分组
- oracle 按照周 分组
- java 按照每周分组
- Oracle按照年月日分组
- Anroid(仿虎扑体育)ListView中数据按照时间\日期分组(分类)
- 按照姓名分组 MS SQL2000
- storm fieldsGrouping按照字段分组
- sql按照首字符分组
- SQL-按照最新时间分组
- mysql 按照年龄段分组查询
- js按照首字母分组排序
- sqlite日期
- 完成按照日期排列
- Sqlite 分组查询
- 常用日期分组统计数据
- FileUtils
- hdu 1556 Color the ball
- HDU 2203 亲和串
- SQLite的优化方案
- mysql宽字符注入
- SQLite 按照日期分组
- 黑马程序员——Gui
- ubuntu安装配置JDK(亲测)
- iOS简介
- handler机制理解
- 面向对象三大特性之多态性
- rac_/home/oracle权限过大引发的节点信任关系错误
- 闭包
- 清理心情,重新学习