SQL乘列值过滤行,并按过滤值创建新列
我在DB中的一项任务有问题 我正在将数据从plc
加载到db(mysql
),并且它们被读取,因为
id,timestamp,name,value.
我必须以形式进行读取:
timestamp,value1, value2, value 3 etc
值需要通过名称值来完成。
我的实际选择结果
ID | TIMESTAMP | 名称 | 值 |
---|---|---|---|
1 | 2022-02-16 16:38:49 | PT_TS1 | 21.5 |
2 | 2022-02-16 | 38:38:49 PT_TS2 | 23.2 |
3 | 2022-02-16 | : | :38:38: 49 |
16 | 16: 38 02-16 16:38:49 | PT_TS4 | 22.2 |
5 | 2022-02-16 16:38:50 | PT_TS5 | 21.0 |
6 | 2022-02-16 16 | 23.2 7 | :38:38 : |
: | 2022-16 | PT_TS6 | 38 |
50 | 2022-02-16 16:38:50 | PT_TS8 | 22.2 |
9 | 2022-02-16 16:38:30 | pt_ts_med | 21.825 |
10 | 2022-02-16 16:38:50 | CCL_RH1 | 37.8514 |
11 | 2022-02-16 | CCL_RH1 | 37.7514 |
12 | 2022-02-16 16:38:30 | VAHU2_SETPOINT | 27.0 |
13 | 2022-02-16 16:40:25 | PT_TS1 | 21.5 |
14 | 2022-02-02-16 16:40:25 | PT_TS2 PT_TS2 | 23.2 23.2 |
15 | 2022-02-02-16 16 16 16 16:40: 25 | PT_TS3 | 21.0 |
16 | 2022-02-16 16:40:25 | PT_TS4 | 22.2 |
17 | 2022-02-16 16:40:25 | 21.0 | 18 |
2022-02-16 | PT_TS5 | 25 | : |
40 | 16:40: 40:25 | PT_TS7 | 20.3 |
20 | 16:40:25 | PT_TS8 | 22.2 |
21 | 16:40:25 | PT_TS_MED | 21.825 |
| 2022-02-16 | 2022-02-16 | 21.825 |
22 | 2022-02-02-16 16:40:25 | CCL_RH2 | 37.7697 |
24 | 2022-02-16 16:40:25 | VAHU2_SETPOINT | 27.0 |
我想拥有这样的东西:
|TimeStamp |PT_TS1 |PT_TS2 |PT_TS3 |PT_TS4 |PT_TS5 |PT_TS6 |PT_TS6 |PT_TS7 |PT_TS8 |
I have a problem with one task in a DB
I'm loading data from plc
to DB (mySql
), and they are read as
id,timestamp,name,value.
I have to make it in form:
timestamp,value1, value2, value 3 etc
filtering for value need to be done by name value
My actual select result
ID | Timestamp | Name | Value |
---|---|---|---|
1 | 2022-02-16 16:38:49 | PT_TS1 | 21.5 |
2 | 2022-02-16 16:38:49 | PT_TS2 | 23.2 |
3 | 2022-02-16 16:38:49 | PT_TS3 | 21.0 |
4 | 2022-02-16 16:38:49 | PT_TS4 | 22.2 |
5 | 2022-02-16 16:38:50 | PT_TS5 | 21.0 |
6 | 2022-02-16 16:38:50 | PT_TS6 | 23.2 |
7 | 2022-02-16 16:38:50 | PT_TS7 | 20.3 |
8 | 2022-02-16 16:38:50 | PT_TS8 | 22.2 |
9 | 2022-02-16 16:38:50 | PT_TS_med | 21.825 |
10 | 2022-02-16 16:38:50 | Ccl_RH1 | 37.8514 |
11 | 2022-02-16 16:38:50 | Ccl_RH2 | 37.7514 |
12 | 2022-02-16 16:38:50 | vAhu2_SetPoint | 27.0 |
13 | 2022-02-16 16:40:25 | PT_TS1 | 21.5 |
14 | 2022-02-16 16:40:25 | PT_TS2 | 23.2 |
15 | 2022-02-16 16:40:25 | PT_TS3 | 21.0 |
16 | 2022-02-16 16:40:25 | PT_TS4 | 22.2 |
17 | 2022-02-16 16:40:25 | PT_TS5 | 21.0 |
18 | 2022-02-16 16:40:25 | PT_TS6 | 23.2 |
19 | 2022-02-16 16:40:25 | PT_TS7 | 20.3 |
20 | 2022-02-16 16:40:25 | PT_TS8 | 22.2 |
21 | 2022-02-16 16:40:25 | PT_TS_med | 21.825 |
22 | 2022-02-16 16:40:25 | Ccl_RH1 | 37.8697 |
23 | 2022-02-16 16:40:25 | Ccl_RH2 | 37.7697 |
24 | 2022-02-16 16:40:25 | vAhu2_SetPoint | 27.0 |
I would want to have something like this:
|TimeStamp |PT_TS1 |PT_TS2 |PT_TS3 |PT_TS4 |PT_TS5 |PT_TS6 |PT_TS6 |PT_TS7 |PT_TS8 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我设法做了这样的事情:
它有效,但是现在我有问题,我需要在最近的时间戳上加入行。有时我的时间戳在一个周期中是不同的。我的意思是,有54秒和第二个55 s。有什么方法
Okay so i manage to do something like that:
and it works, but now i have problem, that i need join rows by nearest timestamp. Sometimes my timestamp is diffrent in one cycle. i mean, that one have 54s and second 55 s. is any way to do that