sqlite中的第一个和最后一个函数

sqlite中的第一个和最后一个函数,sql,database,sqlite,analytics,Sql,Database,Sqlite,Analytics,我想得到每组的第一个和最后一个日期。 我找不到它的文档 基本上,该表如下所示: select start, --timestamp first(open) partition by start order by asc, max(high), min(low), last(close) partition by start order by asc from candles_USDT_BTC group by round(start/

我想得到每组的第一个和最后一个日期。 我找不到它的文档

基本上,该表如下所示:

select start, --timestamp
       first(open) partition by start order by asc, 
       max(high), 
       min(low), 
       last(close) partition by start order by asc
from candles_USDT_BTC
group by round(start/1800); --group by 15 min

当然,第一个和最后一个函数并不存在,只是为了让大家了解……您可以使用相关子查询查找组中具有最小/最大值的行:

SELECT start,
       (SELECT open
        FROM candles_USDT_BTC AS c2
        WHERE round(c2.start / 1800) = round(candles_USDT_BTC.start / 1800)
        ORDER BY start ASC
        LIMIT 1),
       max(high),
       min(low),
       (SELECT close
        FROM candles_USDT_BTC AS c2
        WHERE round(c2.start / 1800) = round(candles_USDT_BTC.start / 1800)
        ORDER BY start DESC
        LIMIT 1)
FROM candles_USDT_BTC
GROUP BY round(start / 1800);

您可以使用附加的
join
s:

select cub.s, cub.max_high, cub.min_low, f.open, l.close
from (select round(start/1800) as s, max(high) as max_high, min(low) as min_low,
             min(start) as first_start,
             max(start) as last_start
      from candles_USDT_BTC
      group by round(start/1800)
     ) cub join
     candles_USDT_BTC f
     on f.start = cub.first_start join
     candles_USDT_BTC l
     on l.start = cub.last_start;