gpt4 book ai didi

mysql - 如何使用 MYSQL 将数据分成 3 个不同的时间(24 小时)框架

转载 作者:行者123 更新时间:2023-11-29 14:38:36 24 4
gpt4 key购买 nike

首先,我使用的是 SQL。仅 SQL 查询语言。我正在使用 MYSQL 工作台提取我的项目所需的一些功能。我已成功提取所需的功能并将其存储在一个名为新事件的新表中。我还将时间转换为整数。下面是使用的sql代码:-

select iphdr.cid ,iphdr.ip_dst, date(event.timestamp), convert(time(event.timestamp), unsigned) as newtime, event.signature 
from iphdr, event
where iphdr.cid = event.cid
order by event.signature;

结果(部分输出)

cid |ip_add      |date        |newtime|sig. 480 | 3232284675 | 2011-11-19 |4328   | 1   482 | 3232284675 | 2011-11-19 |4328   | 1   1   | 3232284675 | 2011-11-19 |113928 | 1   2   | 3232284675 | 2011-11-19 |235959 | 2   

Since I have converted the time into numeric; hence newtime, now i need to segregate the output form the query above into three different time frame within the period of 24 hours (time frame 0 , 1 and 2). Here is the problem .... when i try to do it using the codes (below) i keep getting the 1064 error code. I thought that by using IF then Else , i could easily separate the data into 3 different time frame.The output i need is like below

cid |ip_add      |date        |newtime|sig.   |time Frame480 | 3232284675 | 2011-11-19 | 4328  | 1  | 0482 | 3232284675 | 2011-11-19 |4328   | 1  | 01   | 3232284675 | 2011-11-19 |113928 | 1  | 12   | 3232284675 | 2011-11-19 |235959 | 2  | 2

Below is the code i used was suppose to do that, however i keep getting error code 1064.

 select newtime from new_event for every row
IF newtime < 80101
than newtime = 0
else if newtime > 80000 and newtime < 160101 than newtime = 1
else if newtime >160000 than newtime = 2
end if

我希望我说得更有意义。在编程方面我是个十足的笨蛋。对不起 。我也试图通过浏览网络来完成这项工作。我会一边努力一边等待您的回复。

最佳答案

if (newtime>160000, 2, if(newtime>80000, 1, 0))

我之前误解了,如果你不想突破 8 小时的框架,
以上应该有帮助

关于mysql - 如何使用 MYSQL 将数据分成 3 个不同的时间(24 小时)框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8463062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com