带时间戳的数据库,显示不同的月份

发布于 2025-01-04 12:22:46 字数 393 浏览 1 评论 0 原文

我有一个表,每 15 分钟保存我的上传/下载统计信息。

这就是表格的样子

| ID  | timestamp  | upload | download | packetssent | packetsreceived 
| 1   | 1328828401 | 343245 | 93473463 | 4343423     | 3435664
| 2   | 1328829301 | 343245 | 93473463 | 4343423     | 3435664

我想要的是当您首先进入页面时您会看到总下载/上传。然后是可用月份的列表。 (所以目前只有二月),一旦您单击一个月,它将显示当天及其总计,当您单击一天时,您将看到该日的所有记录

我需要建议如何执行此操作。

提前致谢

I have a table that saves my upload / download statistics per 15 minutes.

This is what the table looks like

| ID  | timestamp  | upload | download | packetssent | packetsreceived 
| 1   | 1328828401 | 343245 | 93473463 | 4343423     | 3435664
| 2   | 1328829301 | 343245 | 93473463 | 4343423     | 3435664

What i want is when you come first on the page you see total download/upload. And then a list of the months available. (So currently is that only February), Once you click on a month, it wil show the day's and their totals, when you click on a day, you will see all records for that single day

I need advice how to do this.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靑春怀旧 2025-01-11 12:22:46

要提取各种值,请使用 MySQL 中的日期/时间函数

DAY(from_unixtime(timestamp))
MONTH(from_unixtime(timestamp))
YEAR(from_unixtime(timestamp))

HOUR(FROM_UNIXTIME(timestamp))
MINUTE(FROM_UNIXTIME(timestamp))
SECOND(FROM_UNIXTIME(timestamp))

您可以在 group by 部分中使用这些函数来提取取决于各种时间范围的信息

看一下:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html 查看完整列表

To extract the various values, use the date/time functions in MySQL

DAY(from_unixtime(timestamp))
MONTH(from_unixtime(timestamp))
YEAR(from_unixtime(timestamp))

HOUR(FROM_UNIXTIME(timestamp))
MINUTE(FROM_UNIXTIME(timestamp))
SECOND(FROM_UNIXTIME(timestamp))

You can use these in group by sections to extract your information dependent on a variety of time frames

Have a look at: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html for a full list

亽野灬性zι浪 2025-01-11 12:22:46

尝试以下操作(针对当前年份):

SELECT 
   FROM_UNIXTIME(timestamp, "%m") AS m, 
   FROM_UNIXTIME(timestamp, "%Y") AS Y, 
   SUM(packetssent ) AS sent, 
   SUM(packetsreceived) AS received
FROM atable
GROUP BY Y, m HAVING Y=YEAR(NOW())

Try the following (for the current year):

SELECT 
   FROM_UNIXTIME(timestamp, "%m") AS m, 
   FROM_UNIXTIME(timestamp, "%Y") AS Y, 
   SUM(packetssent ) AS sent, 
   SUM(packetsreceived) AS received
FROM atable
GROUP BY Y, m HAVING Y=YEAR(NOW())
岛徒 2025-01-11 12:22:46

我认为你可以使用

SELECT DISTINCT MONTH(DATE(timestamp)) FROM Table.

你可能会逃脱

SELECT DISTINCT MONTH(timestamp) FROM table.

但如果你可以 文档 没有说明您可以向其传递时间戳。

I think you can use

SELECT DISTINCT MONTH(DATE(timestamp)) FROM Table.

You might get away with

SELECT DISTINCT MONTH(timestamp) FROM table.

but if you can the documentation for the MONTH() function doesn't state that you can pass a timestamp to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文