光标是执行此操作的唯一方法吗?
我正在翻阅我拥有的一些原始数据。数据存储在 MySQL 数据库中。数据以逐毫秒的格式列出了当前正在发生的许多可能的“事件”中的哪些。它只有几列:
- id - 行
- 事件的唯一标识符 - 指示当前正在发生哪个事件
我想做的是获取有关这些数据的一些基本信息。具体来说,我想创建一个表,其中包含:
- 事件开始的 id
- 事件结束的 id
- 索引事件及其发生的新 id,以及详细说明当前发生的事件的列。
我知道使用 PHP 很容易处理,只需使用一个简单的循环遍历所有记录,但我试图在这里突破我的 MySQL 知识的界限(这可能很危险,我知道!! )。
所以,我的问题是:光标是最好的选择吗?我问,因为事件可能会发生多次,所以按事件类型进行分组之类的操作将不起作用 - 或者会吗?我只是想知道是否有一种聪明的方法来处理我错过的这个问题,而无需按顺序遍历每一行。
谢谢!
I'm in the process of churning through some raw data that I have. The data are in a MySQL database. The data lists, in a millisecond-by-millisecond format, which of a number of possible 'events' are currently happening. It has only a few columns:
- id - unique identifier for the row
- event - indicates which event is currently occurring
What I would like to do is get some basic information regarding these data. Specifically, I'd like to create a table that has:
- The id that an event starts
- The id that an event ends
- A new id indexing the events and their occurrence, as well as a column detailing which event is currently happening.
I know that this would be easy to deal with using PHP, just using a simple loop through all the records, but I'm trying to push the boundaries of my MySQL knowledge for a bit here (it may be dangerous, I know!!).
So, my question is this: would a cursor be the best thing to use for this? I ask because events can occur multiple times, so doing something like grouping by the event type won't work - or will it? I'm just wondering if there is a clever way of dealing with this I have missed, without needing to go through each row sequentially.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了演示我之前评论的内容,假设您有下表:
收集此信息非常简单:
To demonstrate what I commented earlier about, say you have the following table:
Gathering this information is as simple as: