1
我有一个表称为原稿一个sqlite3的数据库:如何通过选择使用sqlite3来执行多个连接/组?
CREATE TABLE orig (sdate date, stime integer, orbnum integer);
我想要做的就是选择第一个日期/时间为每个orbnum。唯一的问题是stime将时间视为非常尴尬的整数。
假设一个六位数字,前两位数字显示小时,3./4。显示分钟数,最后两位数字显示秒数。所以12345的值是1:23:45,而123456的值是12:34:56。
我想我会这样做使用两个嵌套连接/组语句,但不知何故我不能让它正常工作。下面是我到目前为止有:
select s.orbnum, s.sdate, s.stime
from (
select t.orbnum, t.sdate, t.stime, min(t.sdate) as minsdate
from (
select orbnum, sdate, stime, min(stime) as minstime
from scia group by orbnum, sdate
) as t inner join orig as s on s.stime = t.minstime and s.sdate = t.sdate and s.orbnum = t.orbnum
) as d inner join scia as s on s.stime = d.stime and s.sdate = minsdate and s.orbnum = d.orbnum
where s.sdate >= '2002-08-01' limit 0,200;
这是我的错误:
Error: no such column: t.orbnum
我敢肯定,这只是一些愚蠢的错误,但实际上,我是很新的SQL ...
任何帮助是极大的赞赏:)
编辑:
修复了明显的拼写错误后,查询运行 - 但返回一个空的结果集。然而,这个表格包含大约10年的数据,每天大约12个orbnums,每个orbnum大约有4-5个不同的时间。所以我猜在查询的逻辑中有一些错误...
谢谢,我现在觉得有点愚蠢。但它并没有真正的帮助。该查询返回一个空的结果集,即使它不应该。请参阅编辑。 – 2010-08-31 12:15:31