Обсуждение: insert question..

Поиск
Список
Период
Сортировка

insert question..

От
"Williams, Travis L, NPONS"
Дата:
I'm looking for an example on how to insert static data and information from a select at the same time..

currently I'm doing:

insert into performance (start,finish) select min(poll_time),max(poll_time) from poll

I need to add a 3rd field that is static so I would have something like this


insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

Thanks,

Travis

Re: insert question..

От
Bruno Wolff III
Дата:
On Wed, Jun 11, 2003 at 10:45:05 -0400,
  "Williams, Travis L, NPONS" <tlw@att.com> wrote:
> I'm looking for an example on how to insert static data and information from a select at the same time..
>
> currently I'm doing:
>
> insert into performance (start,finish) select min(poll_time),max(poll_time) from poll
>
> I need to add a 3rd field that is static so I would have something like this
>
>
> insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

If travis is really a constant then you could do:
insert into performance (name,start,finish)
  select 'travis', min(poll_time), max(poll_time) from poll;

Another option that might be faster (if there is an index on poll_time)
because you are using max and min is:
insert into performance (name,start,finish)
  values ('travis',
    (select poll_time from poll order by poll_time limit 1),
    (select poll_time from poll order by poll_time desc limit 1))

Re: insert question..

От
Thomas Kellerer
Дата:

Williams, Travis L, NPONS schrieb:
> I'm looking for an example on how to insert static data and information from a select at the same time..
>
> currently I'm doing:
>
> insert into performance (start,finish) select min(poll_time),max(poll_time) from poll
>
> I need to add a 3rd field that is static so I would have something like this
>
>
> insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll
>

insert into performance (name,start,finish)
select 'Travis', min(poll_time),max(poll_time) from poll

Cheers



Re: insert question..

От
Dmitry Tkach
Дата:
Williams, Travis L, NPONS wrote:

>I'm looking for an example on how to insert static data and information from a select at the same time..
>
>currently I'm doing:
>
>insert into performance (start,finish) select min(poll_time),max(poll_time) from poll
>
>I need to add a 3rd field that is static so I would have something like this
>
>
>insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll
>
Almost :-)

The correct syntax is:

insert into performance (name,start,finish) select 'travis', min(poll_time),max(poll_time) from poll;

I hope, it helps.

Dima