刘狗 2021-03-03 16:19 采纳率: 0%
浏览 86

分时统计各小区用户停车数

字段:用户id, 日期,开始停车时间,结束停车时间,小区id   ,进行分时间段统计各小区各用户的停车数

----------------------------------------------------------------------------------------------------------------------------------------------------------

user_id       |      date                  |        start_time            |      end_time           |  community_id       |        表名:user_parking_record
String          |      yyyy-MM-dd     |        hh:mm:ss            |       hh:mm:ss         |       String

----------------------------------------------------------------------------------------------------------------------------------------------------------

  • 写回答

1条回答 默认 最新

  • 罗浮魅影 2021-03-15 23:47
    关注

    问题描述好像不够明确。以下查询为根据自定义时间段,统计历史停车数。如果是其他情况可根据这个语句进行调整

    /*问题描述好像不够明确。
    以下查询为根据自定义时间段,统计历史停车数。
    时间字段类型是什么?字符串类型可直接截取,如果是时间类型还需要用to_char函数转换。
    另外是什么数据库?不同数据库函数也会有个别差异。
    如果是其他情况可根据这个语句进行调整*/
    select date as 日期 ,community_id as 小区id,
    count(case when substr(start_time,5) < '08:30') as 零点到八点半停车数,
    count(case when substr(start_time,5) >= '08:30' and substr(start_time,2) < '12') as 八点半之后到十二点停车数,
    count(case when substr(start_time,2) >= '12') as 十二点之后停车数
      from user_parking_record t 
     where date between 'yyyy-MM-dd' and 'yyyy-MM-dd' /*统计日期范围*/
     group by date,community_id;
    评论

报告相同问题?

悬赏问题

  • ¥15 单纯型python实现编译报错
  • ¥15 c++2013读写oracle
  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音