V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wuwukai007
V2EX  ›  Python

mysql 两列(两个字段分别开始时间,结束时间)日期,结束时间-开始时间,然后按每半小时分组统计数量

  •  
  •   wuwukai007 · 2021-12-17 14:14:07 +08:00 · 2034 次点击
    这是一个创建于 832 天前的主题,其中的信息可能已经有所发展或是发生改变。

    结束时间-开始时间 按每半小时分组统计数量,求 sql 大佬指点一下

    • 日期是两列字段 start_date,end_date,不是一列
    • 分组是一天 24 小时 中左右半小时 end_date 2:30 到 start_date 3:00 内数量
    4 条回复    2021-12-28 11:20:06 +08:00
    wolfie
        1
    wolfie  
       2021-12-17 14:21:04 +08:00
    四舍五入 分组啊。
    AlexLokhart
        2
    AlexLokhart  
       2021-12-17 15:13:53 +08:00
    很久没手写了,说下思路;两个时间转分钟再除以 30 ,时间 A 和时间 B 除完是一对数字,对应一个时间段,比如 3:4 ,1:9 , 作为子查询的列,然后外层查询 group by 这几列即可
    onhao
        3
    onhao  
       2021-12-17 15:43:42 +08:00
    我觉得,你得搞一个自定义函数来得到具体的时间值属于那半个小时 (如 30 之前算 a,30 之后为 b ) 返回的值 分钟的值 只有 00 或者 30 这样 再 group by 就好了。
    自定义函数类似的写法 https://wuhao.pw/archives/277/
    ssysanny
        4
    ssysanny  
       2021-12-28 11:20:06 +08:00
    这啥坛呀,刚来不能回复,我就郁闷了,这有什么意思呢,到底这论坛是怎么想的呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1657 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 16:47 · PVG 00:47 · LAX 09:47 · JFK 12:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.