doutui2016 2013-05-24 00:03
浏览 47

codeigniter活动记录根据小时数和状态查询结果

I have two queries ultimately I think they will be in the same context of the other but in all. I have a user database that I want to pull out for tracking records based on hour. Example registrations per hour. But in this registrations per hour I want to have the query to dump results by hour increments (or weeks, or months) ie: 1,000 regitrations in november, 1,014 in december and so on, or similar for weeks hours.

I also have a similar query where I want to generate a list of states with the counts next to them of how many users I have per state.

My issue is, I'm thinking I think to one dimensionally currently cause the best idea I can think of at the moment is making in the case of the states 50 queries, but I know thats insane, and there has to be an easier way thats less intense. So thats what Im hoping someone from here can help me with, by giving me a general idea. Cause I don't know which is the best course of action for this currently.. be it using distinct, group_by or something else.

  • 写回答

1条回答 默认 最新

  • dslfjrmz70457 2013-05-24 01:45
    关注

    Experiment a bit and see if that doesn't help you focus on the question a bit more.

    Try selecting from your registrations per hour table and appending the time buckets you are interested in to the select list.

    like this:

    select userid, regid, date_time, week(date_time), year(date_time), day(date_time)
    from registraions;
    

    you can then roll up and count things in that table by using group by and an aggregate function like this:

    select count(distinct userid), year(date_time)
    from registraions
    group by year(date_time)
    

    Read about about date time functions: MySQL Date Time Functions

    Read about aggregate functions" MySQL Group By

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)