我有一个表,我需要为该fk_fc_id
字段选择所有具有空值的行(作为删除它们的前奏),
Column | Type | Modifiers
---------------+-----------------------------+------------------------------------------------------------
di_timestamp | timestamp without time zone |
di_item_value | character varying(10) |
fk_fc_id | integer |
di_id | integer | not null default nextval('data_item_di_id_seq1'::regclass)
Run Code Online (Sandbox Code Playgroud)
然而这行不通
# select fk_fc_id,di_timestamp,di_item_value from data_item where fk_fc_id="";
ERROR: zero-length delimited identifier at or near """"
LINE 1: ...di_timestamp,di_item_value from data_item where fk_fc_id="";
^
Run Code Online (Sandbox Code Playgroud)
尝试Null
也没有用。
如果有人对如何对此进行排序有任何建议,我将不胜感激。
我创建了一个像这样的表:
create table doki_data_item2 (like doki_data_item including defaults);
Run Code Online (Sandbox Code Playgroud)
但是这个新表使用与旧表相同的顺序。
所以两个问题:
我有这个查询,我想开始工作。我试图在某个非空的日期之后计算外键的所有实例,然后将其与原始表的不同之处连接起来,这样我就可以看到没有条目的变量。这是我的查询:
select fulllist.fk_fc_id
from
(
select distinct fk_fc_id
from data_item
) as fulllist
left outer join
(
select temp.fk_fc_id, count(*) as number
from
(
select *
from data_item
where di_item_value not like 'Null'
and di_timestamp > '2013-11-01 00:00:00'
) as temp
group by fk_fc_id
) as lj
on lj.fc_fk_id=fulllist.fk_fc_id;
Run Code Online (Sandbox Code Playgroud)
错误是
错误:列 lj.fc_fk_id 不存在
第 19 行:在 lj.fc_fk_id=fulllist.fk_fc_id 上;
我有一个存储传感器数据的表(在 SQLite 中),看起来像这样;
TABLE Timestream:
idTimestream PK autoincrementing integer,
time int not null,
value float not null,
idSensor integer not null FK
Run Code Online (Sandbox Code Playgroud)
一些但并非所有传感器都有匹配时间,但我只会考虑那些有匹配时间的传感器。我想要做的是将表格重新排列为以下格式,基于查询中列出的一组传感器,而不是表格中的全部:
Time Sensor1 Sensor2 etc.
Run Code Online (Sandbox Code Playgroud)
我正在考虑创建一个临时表,然后插入时间和第一列,然后对时间进行连接以进行后续查询,最后选择整个批次。但这听起来效率不高,我想知道是否有更好的方法?