Re: self join

From: Euler Taveira <euler(at)timbira(dot)com(dot)br>
To: francis(dot)ebbs(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: self join
Date: 2019-04-10 23:34:59
Message-ID: CAHE3wgjL5nT5HqGB8=cUiPV6q=oXhs0CSOaea-e2fOxmOf=JBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Em qua, 10 de abr de 2019 às 09:23, PG Doc comments form
<noreply(at)postgresql(dot)org> escreveu:
>
> The example of self join shows two resulting records.
> I have checked the input data.
> There are three output records with lower lo and higher high temperatures
>
> We seem to be missing, in the answer, a third record:
> ( (San Francisco, 46, 50) , (Hayward, 54, 37 ))
>
No, it is not. See src/tutorial/basics.source. I reproduce some
commands of that file above. Note that that self join returns only 2
records.

CREATE TABLE weather (
city varchar(80),
temp_lo int, -- low temperature
temp_hi int, -- high temperature
prcp real, -- precipitation
date date
);

CREATE TABLE cities (
name varchar(80),
location point
);

INSERT INTO weather
VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');

INSERT INTO cities
VALUES ('San Francisco', '(-194.0, 53.0)');

INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)
VALUES ('San Francisco', 43, 57, 0.0, '1994-11-29');

INSERT INTO weather (date, city, temp_hi, temp_lo)
VALUES ('1994-11-29', 'Hayward', 54, 37);

SELECT W1.city, W1.temp_lo, W1.temp_hi,
W2.city, W2.temp_lo, W2.temp_hi
FROM weather W1, weather W2
WHERE W1.temp_lo < W2.temp_lo
and W1.temp_hi > W2.temp_hi;

--
Euler Taveira Timbira -
http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

In response to

  • self join at 2019-04-10 09:19:20 from PG Doc comments form

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2019-04-11 17:26:11 Re: Small mistake (grammar/wording)
Previous Message Andres Freund 2019-04-10 20:47:47 Re: 30.3. Asynchronous Commit