Re: [SQL] SQL Subqueries on each result row

2009-09-24 Thread Mark J Camilleri
On Wed, Sep 23, 2009 at 6:33 PM, Jim wrote: > On Sep 23, 5:43 am, AnthonyV wrote: > > Hello, > > > > I have a table like : > > > >date|value > > --- > > 2009-09-19 | 1 > > 2009-09-20 | 2 > > 2009-09-21 | 6 > > 2009-09-22 | 9 > > 200

Re: [SQL] SQL Subqueries on each result row

2009-09-23 Thread Jim
On Sep 23, 5:43 am, AnthonyV wrote: > Hello, > > I have a table like : > >    date        |    value > --- > 2009-09-19 |      1 > 2009-09-20 |      2 > 2009-09-21 |      6 > 2009-09-22 |      9 > 2009-09-23 |      1 > > I'd like a request which gives me the sum of each

[SQL] SQL Subqueries on each result row

2009-09-23 Thread AnthonyV
Hello, I have a table like : date|value --- 2009-09-19 | 1 2009-09-20 | 2 2009-09-21 | 6 2009-09-22 | 9 2009-09-23 | 1 I'd like a request which gives me the sum of each last n days. For example, if I want the sum of each 3 days,

Re: [SQL] Subqueries

2008-10-31 Thread Gregory Stark
"Pascal Tufenkji" <[EMAIL PROTECTED]> writes: > I understand the fact that "the inner query is executed before the outer > query and the inner query doesn't even know about the outer query." > > But why the following query can be executed, although the inner query is > using the outer query. > >

Re: [SQL] Subqueries

2008-10-31 Thread Pascal Tufenkji
53 PM To: [EMAIL PROTECTED] Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Subqueries The "v" reference need to exist in the inner query. You can't use an "outer query reference" in the inner query. This happens because the inner query is executed before the outer query and

Re: [SQL] Subqueries

2008-10-30 Thread Helio Campos Mello de Andrade
The "v" reference need to exist in the inner query. You can't use an "outer query reference" in the inner query. This happens because the inner query is executed before the outer query and the inner query doesn't even know about the outer query. May be this helps you get what you want. SELECT *,

Re: [SQL] Subqueries

2008-10-30 Thread Oliveiros Cristina
alias v not visible in sub-query? - Original Message - From: Pascal Tufenkji To: pgsql-sql@postgresql.org Sent: Thursday, October 30, 2008 12:17 PM Subject: [SQL] Subqueries Hello, I don't understand the following error. Can anyone help me plz Thx P

[SQL] Subqueries

2008-10-30 Thread Pascal Tufenkji
Hello, I don't understand the following error. Can anyone help me plz Thx Pascal select * from sip_vacations_v v left join ( select pe.emp_id,mg.mat_id,mg.groupe,count(p.id) * 1.5 as nb_heures from mat_grp_v mg inner join planification_v p on p.mat_grp_id = mg.id

Re: [SQL] Subqueries returning more than one value?

2004-05-11 Thread CoL
hi, Adam Witney wrote, On 5/11/2004 02:09: Hi, I am using a function in a subquery, this works ok: SELECT name, (SELECT p_my_func(1)) AS id FROM test; However I would like to have the function return 2 values into the main query... Something like this: SELECT name, (SELECT p_my_func(1)) AS (id

[SQL] Subqueries returning more than one value?

2004-05-10 Thread Adam Witney
Hi, I am using a function in a subquery, this works ok: SELECT name, (SELECT p_my_func(1)) AS id FROM test; However I would like to have the function return 2 values into the main query... Something like this: SELECT name, (SELECT p_my_func(1)) AS (id, type) FROM test; Of course this give

Re: [SQL] SQL subqueries newbie help

2003-09-07 Thread Tom Lane
Rod Taylor <[EMAIL PROTECTED]> writes: > Oh yeah, sorry. It needs to be like that because otherwise it is unsure > what value to use for event. What you really want is a min function > that runs a min on date, and returns the appropriate event -- which > doesn't exist, but I believe could be crea

Re: [SQL] SQL subqueries newbie help

2003-09-07 Thread Alexei Chetroi
On Sun, Sep 07, 2003 at 09:09:35AM -0400, Rod Taylor wrote: > [skip] > > > > Thanks everybody for responses. I'm trying this one, but psql complains > > on queries like "SELECT min(date), event FROM events GROUP BY item" that > > events must be GROUPed or used in an aggregate function. Why thi

Re: [SQL] SQL subqueries newbie help

2003-09-07 Thread Rod Taylor
On Sun, 2003-09-07 at 07:42, Alexei Chetroi wrote: > On Sat, Sep 06, 2003 at 01:21:36PM -0400, Rod Taylor wrote: > > > I'd like to write a query which returns following information regarding > > > each item: item, date of very first event, very last event. > > > Is this possible? I think I can wr

Re: [SQL] SQL subqueries newbie help

2003-09-07 Thread Alexei Chetroi
On Sat, Sep 06, 2003 at 01:21:36PM -0400, Rod Taylor wrote: > > I'd like to write a query which returns following information regarding > > each item: item, date of very first event, very last event. > > Is this possible? I think I can write several SELECT queries and > > procces them by an appli

Re: [SQL] SQL subqueries newbie help

2003-09-06 Thread Rod Taylor
> I'd like to write a query which returns following information regarding > each item: item, date of very first event, very last event. > Is this possible? I think I can write several SELECT queries and > procces them by an application or possibly write some procedure, but > what is better soluti

Re: [SQL] SQL subqueries newbie help

2003-09-06 Thread Bruno Wolff III
On Sat, Sep 06, 2003 at 14:07:09 +0300, Alexei Chetroi <[EMAIL PROTECTED]> wrote: > Hi All, > > I need a little help regarding writing some subqueries. For example I > have a table "items" which contains columns: itemid, description; and > another table "events" with columns: itemid, date, eve

[SQL] SQL subqueries newbie help

2003-09-06 Thread Alexei Chetroi
Hi All, I need a little help regarding writing some subqueries. For example I have a table "items" which contains columns: itemid, description; and another table "events" with columns: itemid, date, event. events.itemid references items.itemid. Table events contains events regarding some itemid'

Re: [SQL] sql subqueries problem

2002-08-20 Thread Mathieu Arnold
>> I've tried, but, as the subselect is an aggregate, I can't get it (maybe >> I don't know enough about it to do it :) > > Right, that'd make it harder. :) > > Hmm, would something like: > > FROM > (select *, > (select sum(ff.montant_ttc/df.taux) from facture ff join > devise as df using

Re: [SQL] sql subqueries problem

2002-08-20 Thread Stephan Szabo
On Tue, 20 Aug 2002, Mathieu Arnold wrote: > --On lundi 19 août 2002 09:45 -0700 Stephan Szabo > <[EMAIL PROTECTED]> wrote: > > > > > On Mon, 19 Aug 2002, Mathieu Arnold wrote: > > > >> Hi > >> > >> I have my accounting in a database, and I have a problem with subqueries, > >> here is what I have

Re: [SQL] sql subqueries problem

2002-08-19 Thread Mathieu Arnold
--On lundi 19 août 2002 09:45 -0700 Stephan Szabo <[EMAIL PROTECTED]> wrote: > > On Mon, 19 Aug 2002, Mathieu Arnold wrote: > >> Hi >> >> I have my accounting in a database, and I have a problem with subqueries, >> here is what I have : >> >> >> >> SELECT f.numero, >> f.id_clie

Re: [SQL] sql subqueries problem

2002-08-19 Thread Stephan Szabo
On Mon, 19 Aug 2002, Mathieu Arnold wrote: > Hi > > I have my accounting in a database, and I have a problem with subqueries, > here is what I have : > > > > SELECT f.numero, > f.id_client, > f.date_creation, > (f.date_creation + (f.echeance_paiement||' days')::inter

[SQL] sql subqueries problem

2002-08-19 Thread Mathieu Arnold
Hi I have my accounting in a database, and I have a problem with subqueries, here is what I have : SELECT f.numero, f.id_client, f.date_creation, (f.date_creation + (f.echeance_paiement||' days')::interval)::date AS echeance, f.montant_ttc, ROUND(

Re: [SQL] Subqueries in select clause

2001-04-18 Thread Tom Lane
"Josh Berkus" <[EMAIL PROTECTED]> writes: > Until you can upgrade, though, try this approach: > CREATE VIEW c_aggregate AS > SELECT sum(a) as sum_a, b FROM c GROUP BY b; > SELECT max(sum_a) FROM c_aggregate; Unfortunately that won't work in 7.0 --- grouped views have a lot of problems in that v

Re: [SQL] Subqueries in select clause

2001-04-18 Thread Josh Berkus
Sara, Hey! Great to see that Postgres has made it to Israel. What's the most popular Linux distribution there? I think you have your answer ... an upgrade. RPMs for most major distributions of Linux should be available within the week. Until you can upgrade, though, try this approach: CREA

Re: [SQL] Subqueries in select clause

2001-04-18 Thread Richard Huxton
Sara Cohen <[EMAIL PROTECTED]> said: > Hi, > > I am attempting to use subqueries in the select clause of a query > and am encountering difficulties. > > The Problem: > > > I would like to use a subquery that returns one column, but more than one > tuple. The result of this subquer

Re: [SQL] Subqueries in select clause

2001-04-18 Thread Stephan Szabo
On Wed, 18 Apr 2001, Sara Cohen wrote: > The Problem: > > > I would like to use a subquery that returns one column, but more than one > tuple. The result of this subquery is then used in an aggregate function. > > For example, suppose I have a table c, with columns a and b of > num

Re: [SQL] Subqueries in select clause

2001-04-18 Thread Tom Lane
Sara Cohen <[EMAIL PROTECTED]> writes: > Using Oracle, I could get by this problem with: > select max(d) from ((select count(b) as d from c group by a)); > However, my version of postgres doesn't support subqueries in the from > clause. Time to update to 7.1... rega

[SQL] Subqueries in select clause

2001-04-18 Thread Sara Cohen
Hi, I am attempting to use subqueries in the select clause of a query and am encountering difficulties. The Problem: I would like to use a subquery that returns one column, but more than one tuple. The result of this subquery is then used in an aggregate function. For example, sup

Re: [SQL] Subqueries in Non-SELECT Queries

2000-12-18 Thread Frank Joerdens
Christof Glaser wrote: [ . . . ] > since the where clause compares just one field for equality. You might > try IN instead of =, ie > > update index set level = 2 where parentid in ( select id from > index where level = 1 ); That was it! Thanks, Frank

Re: [SQL] Subqueries in Non-SELECT Queries

2000-12-17 Thread Tom Lane
Frank Joerdens <[EMAIL PROTECTED]> writes: > mpi=# update index set level = 2 where parentid = ( select id from > index where level = 1 ); > ERROR: More than one tuple returned by a subselect used as an expression. Apparently the subquery "select id from index where level = 1" is returning more

Re: [SQL] Subqueries in Non-SELECT Queries

2000-12-17 Thread Christof Glaser
Frank Joerdens wrote: > mpi=# update index set level = 2 where parentid = ( select id from > index where level = 1 ); > ERROR: More than one tuple returned by a subselect used as an > expression. mpi=# > > This is a recursive query, on a single table. Is that not possible? Hi Frank, as the err

[SQL] Subqueries in Non-SELECT Queries

2000-12-17 Thread Frank Joerdens
I am trying to do something that looks to me exactly like what's described in chapter 8.4 in the Postgresql book: test=> UPDATE salesorder test-> SET ship_date = '11/16/96' test-> WHERE customer_id = ( test(> SELECT customer_id test(> FROM customer test(> WHERE name = 'Fleer Gearworks, Inc.' tes

RE: [SQL] subqueries as values in updates

2000-12-08 Thread Francis Solomon
nal Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]On Behalf Of > [EMAIL PROTECTED] > Sent: 08 December 2000 13:00 > To: liste SQL > Subject: [SQL] subqueries as values in updates > > > hello, list. > are subqueries alloved as values in an update

[SQL] subqueries as values in updates

2000-12-08 Thread patrick . jacquot
hello, list. are subqueries alloved as values in an update command ? e.g. update a set a.attribute1 = a.attribute1 + (select sum(b.attribute1) from b where b.attribute2=a.attribute2); If yes, how is the correct syntax ? If not, is there a hope for it in a future version ?

Re: [SQL] Subqueries in from clause

2000-11-03 Thread Tom Lane
Pierre Habraken <[EMAIL PROTECTED]> writes: > It looks like if subqueries in from clause are not supported by > PostgreSQL. Am I right ? If yes, are there any plans to provide this > feature soon ? Already there in current sources for 7.1 ... regards, tom lane

[SQL] Subqueries in from clause

2000-11-03 Thread Pierre Habraken
It looks like if subqueries in from clause are not supported by PostgreSQL. Am I right ? If yes, are there any plans to provide this feature soon ? I would like to use Postgres for teaching SQL as a replacement for a well known commercial product which I find too heavy, too not open source, too e

Re: [SQL] Subqueries in from clause?

2000-09-25 Thread Tom Lane
Meszaros Attila <[EMAIL PROTECTED]> writes: > How far is the above subject from beeing implemented? I'm looking at it right now ... no promises yet, though. regards, tom lane

[SQL] Subqueries in from clause?

2000-09-25 Thread Meszaros Attila
Hi All, My question for this week: How far is the above subject from beeing implemented? (I've run through the archives, and found some quite old mails in this topic. They mentioned automatically generated temp tables as possibe solutions... Is this the plan even today?) Attila Ps.: Two weeks