简体   繁体   English

SQL查询或带列的视图取决于SELECT查询

[英]SQL Query or View with columns depends on SELECT query

My question is maybe silly and will be not so easy to exactly write down. 我的问题可能很愚蠢,很难准确地写下来。 However may example understandable. 但是,示例可能是可以理解的。 I am creating a system logging database, which periodically stores values from a hardwer. 我正在创建一个系统日志记录数据库,该数据库定期存储来自硬件的值。 My tables (in very reduced complexity) are: 我的表(复杂度大大降低)是:

VARIABLES table
id_variable    name_variable
1              Temperatur
2              Voltage
...            ...
n              VariableN

LOG_ROWS table
id_log_row     timestamp
1              2012.01.01. 10:00:00
2              2012.01.01. 10:01:00
3              2012.01.01. 10:02:00
n              2012.01.01. 10:0n:00

LOG_VALUES table
id_log_value   id_log_row    id_variable   value
1              1             1             34
2              1             2             1200
3              2             1             35
4              3             1             36
5              3             2             1230

The data structure is important, because I have to add new variables later wothout alter table and each variable has other storing time period. 数据结构很重要,因为稍后必须在更改表中添加新变量,并且每个变量都有其他存储时间段。 (not all log_rows contains the all variable. Here time period of voltage is 2 min, time period of temperatur is 1 min) (并非所有log_rows都包含all变量。这里电压的时间段为2分钟,温度的时间段为1分钟)

So, I would like to create well readable db view, where the columns are the variable ids or names (here names) joined with log_row's id and timestamp. 因此,我想创建一个易于阅读的数据库视图,其中的列是变量id或名称(此处为名称)以及log_row的id和时间戳。 Something similar to this. 与此类似。

id_log_row    timestamp              Temperatur     Voltage   ...  N
1             2012.01.01. 10:00:00   34             1200           NULL
2             2012.01.01. 10:01:00   35             NULL           NULL
3             2012.01.01. 10:02:00   36             1230      ...  NULL

Is these view possible with SQL? 这些视图可以在SQL中使用吗? To define columns according to table content. 根据表内容定义列。 I am interested in. I want to create this in SQLite 我感兴趣。我想在SQLite中创建它

SQLite does not support altering a view. SQLite不支持更改视图。 It is generally a bad idea to design your data is such a way that you later must alter tables. 设计数据通常是一个坏主意,以至于您以后必须更改表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM