如何根据列值创建视图
我有一个表:
+------+----------+----------+-------+
| id | location | variable | value |
+------+----------+----------+-------+
| 1 | loc1 | outside | 30.6 |
| 2 | loc1 | inside | 22.3 |
| 3 | loc2 | outside | 31.1 |
| 4 | loc2 | inside | 22.2 |
| 5 | loc3 | outside | 34.7 |
| 6 | loc3 | inside | 21.9 |
+------+----------+----------+-------+
是否可以创建以这种方式显示的视图:
+----------+----------+-------+
| location | outside | inside|
+----------+----------+-------+
| loc1 | 30.6 | 22.3 |
| loc2 | 31.1 | 22.2 |
| loc3 | 34.7 | 21.9 |
+----------+----------+-------+
我尝试为每个列“位置”和“位置”和“位置”
获得不同的值,但不知道如何创建一个这些值的列正确填充它们。
I have a table:
+------+----------+----------+-------+
| id | location | variable | value |
+------+----------+----------+-------+
| 1 | loc1 | outside | 30.6 |
| 2 | loc1 | inside | 22.3 |
| 3 | loc2 | outside | 31.1 |
| 4 | loc2 | inside | 22.2 |
| 5 | loc3 | outside | 34.7 |
| 6 | loc3 | inside | 21.9 |
+------+----------+----------+-------+
Is it possible to create view that shows this in this way:
+----------+----------+-------+
| location | outside | inside|
+----------+----------+-------+
| loc1 | 30.6 | 22.3 |
| loc2 | 31.1 | 22.2 |
| loc3 | 34.7 | 21.9 |
+----------+----------+-------+
I tried to Get DISTINCT values for each column "location" and "location"
but don't know how to create a columns with these values populate them correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用条件聚合(取决于当前模型代表整个数据集)
,也可以使用
max
sum> sum ,取决于每个位置< /代码>和
变量
组合。You can use conditional aggregation (depending on the current model represents the whole dataset) like
or replace presumably
MAX
aggregation bySUM
depending whether multiple rows exist for eachlocation
andvariable
combination.