G
G
GLaDosSystem2019-06-05 20:17:26
PostgreSQL
GLaDosSystem, 2019-06-05 20:17:26

Why can't use with?

There is this request:

with min as
  (
   select
   cast(extract(epoch from time) as integer)
   from records 
   where time >= '2016-01-01 06:36:12' 
   order by time asc 
   limit 1
 ), max as (
   select
   cast(extract(epoch from time) as integer)
   from records 
   where time <= '2016-02-01 06:36:12'
   order by time desc
   limit 1
 )

select (max.time - min.time) t1

Why is the following error coming up?
SQL Error [42P01]: ОШИБКА: таблица "max" отсутствует в предложении FROM
  Позиция: 333

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Karo, 2019-06-06
@GLaDosSystem

1) Select queries have a mandatory from part.
2) Columns in tables are not named
Try this:

with min as
  (
   select
   cast(extract(epoch from time) as integer) as time
   from records 
   where time >= '2016-01-01 06:36:12' 
   order by time asc 
   limit 1
 ), max as (
   select
   cast(extract(epoch from time) as integer) as time
   from records 
   where time <= '2016-02-01 06:36:12'
   order by time desc
   limit 1
 )

select (max.time - min.time) t1
from min, max

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question