dsh1956 2014-03-19 22:47
浏览 21
已采纳

使用PHP解决最忙碌的一天

I have a table with a timestamp in unixtimestamp for everytime someone logs into the system. I would like to work out the busiest day.

Im a little lost as to where to start, i believe its that you need to work out a count for each day stored into the database (or some kind of string between start and end of the logs?)

Database Structure for logs

Example :

user  | action         | timestamp
admin | User Logged In | 1395257767

User being "Username"

Action being "User Logged In"

Timestamp being Unixtimestamp given at the time they login to the system.

Any help would be a great start

SQLFiddle - http://sqlfiddle.com/#!2/66d4293

  • 写回答

3条回答 默认 最新

  • dongzhou5344 2014-03-19 22:54
    关注

    Try something like thi.

    SELECT COUNT(*) c, DATE(FROM_UNIXTIME( timestamp) ) day FROM log 
    GROUP BY  day ORDER BY c DESC LIMIT 1;
    

    DATE(FROM_UNIXTIME( timestamp )) converts to a datetime and then a date.

    By the way, you might consider storing your dates as datetime or timestamp structures. Storing as unix timestamps and then having to convert to useable dates is less than ideal.

    http://sqlfiddle.com/#!2/a53d1/2

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入