name time1 time2 time3
a 2007-1-2 2007-1-3 null
b 2007-2-2 2007-2-3 null
b 2007-3-2 null 2007-1-3
b 2007-4-2 null null
c 2007-5-2 2007-1-4 null
c 2007-6-2 2007-1-5 null
a 2007-7-2 2007-1-6 null求一检索,在一定时间段内,显示
name count(time1) count(time2) count(time3)
a 1 1 0
b 3 1 2
c 1 1 0如果在时段内没有数据,全部显示为0谢谢师兄们赐教
a 2007-1-2 2007-1-3 null
b 2007-2-2 2007-2-3 null
b 2007-3-2 null 2007-1-3
b 2007-4-2 null null
c 2007-5-2 2007-1-4 null
c 2007-6-2 2007-1-5 null
a 2007-7-2 2007-1-6 null求一检索,在一定时间段内,显示
name count(time1) count(time2) count(time3)
a 1 1 0
b 3 1 2
c 1 1 0如果在时段内没有数据,全部显示为0谢谢师兄们赐教
解决方案 »
- MySql数据库 恢复删除Delete From
- 关于MYSQL数据库事务处理的问题,大家来讨论下
- 求救:liunx mysql 启动异常 高手看看 折磨我几天了
- MYSQL怎么在WINDOWS2003下使用不了
- 移植错误
- mysql control ceter有中文简体版for windows 2000 吗? BLOG是指什么DD?
- 郁闷啊郁闷, mysql数据库的或者是php程序的问题,搞不清啊。。。
- 请教如何将SQLServer中的数据库、表以及数据导入MySQL啊
- 高分求教-postgresql的function怎么使用?
- mysql创建视图时出现 #1349 - View's SELECT contains a subquery in the FROM clause
- mysql 如何整个库搜索
- 统计用户最小登陆时间
sum(if(time1 between '2009-10-01' and '2019-10-01',1,0)) as `count(time1)`,
sum(if(time2 between '2009-10-01' and '2019-10-01',1,0)) as `count(time2)`,
sum(if(time3 between '2009-10-01' and '2019-10-01',1,0)) as `count(time3)`
from xxxx
where time1 between '2009-10-01' and '2019-10-01'
or time2 between '2009-10-01' and '2019-10-01'
or time3 between '2009-10-01' and '2019-10-01'
group by name
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
sum(if(time1 between '2009-10-01' and '2019-10-01',1,0)) as `count(time1)`,
sum(if(time2 between '2009-10-01' and '2019-10-01',1,0)) as `count(time2)`,
sum(if(time3 between '2009-10-01' and '2019-10-01',1,0)) as `count(time3)`
from xxxx
where time1 between '2009-10-01' and '2019-10-01'
or time2 between '2009-10-01' and '2019-10-01'
or time3 between '2009-10-01' and '2019-10-01'
group by name
//where time1 between '2009-10-01' and '2019-10-01'
//or time2 between '2009-10-01' and '2019-10-01'
//or time3 between '2009-10-01' and '2019-10-01'
这一块不需要