-1

我有一张桌子,我正在尝试获取一些信息。已成功获取信息,但速度很慢。试图找到其他方法来做到这一点。想知道你是否有一些想法。

我想要一个开始日期和一个结束日期。但我只想要它们,如果另一个标签名称在这些日期之间的最大值为 10。

我现在所做的就是写作。此代码有效,但效率不高,因为它遍历了所有可能性。

PLZ帮助

for (select ts as st from history  
    where name='tagg1' and value = '1' and ts between t0 and t1 and request='4')
    do

endDate=(select ts as en from history  where name='tagg2' and ts between st+25:00 and st+40:00 and request ='4' and 
    value='0');

totalsum = (select max from history1 where name='tagg3' and ts between st and endDate )

if totalsum = 10 then
  write st || endDate
end;
4

1 回答 1

1

尝试这个:

SELECT
    T2.*
FROM
    history1 JOIN
    (
        select 
            T1.start,
            ts as end 
        from 
            history JOIN
            (
                select 
                    ts as start
                from 
                    history  
                where 
                    name = 'tagg1' and 
                    value = '1' and 
                    request = '4' and
                    ts between t0 and t1
            ) T1 ON (history.ts BETWEEN T1.start + 25:00 and T1.start + 40:00)
        where 
            name = 'tagg2' and 
            value = '0' and
            request = '4'
    ) T2 ON (history1.ts between start and end)
WHERE
    history1.name = 'tagg3' AND
    max = 10

这个查询应该只返回在你的脚本中打印的记录write st || endDate

于 2013-11-12T14:32:27.780 回答