Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80cd1a6

Browse files
committed
Doc: sync src/tutorial/basics.source with SGML documentation.
basics.source is supposed to be pretty closely in step withthe examples in chapter 2 of the tutorial, but I forgot toupdate it in commitf05a5e0. Fix that, and adjust a coupleof other discrepancies that had crept in over time.(I notice that advanced.source is nowhere near being in syncwith chapter 3, but I lack the ambition to do somethingabout that right now.)
1 parent1ed6f1b commit80cd1a6

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

‎src/tutorial/basics.source

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ SELECT *
7979
WHERE city = 'San Francisco'
8080
AND prcp > 0.0;
8181

82+
-- You can request that the results of a query be returned in sorted order:
83+
84+
SELECT * FROM weather
85+
ORDER BY city, temp_lo;
86+
8287
-- Here is a more complicated one. Duplicates are removed when DISTINCT is
8388
-- specified. ORDER BY specifies the column to sort on. (Just to make sure the
8489
-- following won't confuse you, DISTINCT and ORDER BY can be used separately.)
@@ -111,7 +116,8 @@ SELECT city, temp_lo, temp_hi, prcp, date, location
111116
-- table name. If you want to be clear, you can do the following. They give
112117
-- identical results, of course.
113118

114-
SELECT weather.city, weather.temp_lo, weather.temp_hi, weather.prcp, weather.date, cities.location
119+
SELECT weather.city, weather.temp_lo, weather.temp_hi,
120+
weather.prcp, weather.date, cities.location
115121
FROM weather, cities
116122
WHERE cities.name = weather.city;
117123

@@ -128,8 +134,8 @@ SELECT *
128134
-- Suppose we want to find all the records that are in the temperature range
129135
-- of other records. W1 and W2 are aliases for weather.
130136

131-
SELECT W1.city, W1.temp_lo, W1.temp_hi,
132-
W2.city, W2.temp_lo, W2.temp_hi
137+
SELECT W1.city, W1.temp_lo AS low, W1.temp_hi AS high,
138+
W2.city, W2.temp_lo AS low, W2.temp_hi AS high
133139
FROM weather W1, weather W2
134140
WHERE W1.temp_lo < W2.temp_lo
135141
and W1.temp_hi > W2.temp_hi;
@@ -146,16 +152,27 @@ SELECT city FROM weather
146152
WHERE temp_lo = (SELECT max(temp_lo) FROM weather);
147153

148154
-- Aggregate with GROUP BY
149-
SELECT city, max(temp_lo)
155+
SELECT city,count(*),max(temp_lo)
150156
FROM weather
151157
GROUP BY city;
152158

153159
-- ... and HAVING
154-
SELECT city, max(temp_lo)
160+
SELECT city,count(*),max(temp_lo)
155161
FROM weather
156162
GROUP BY city
157163
HAVING max(temp_lo) < 40;
158164

165+
-- We can filter rows before aggregating them:
166+
SELECT city, count(*), max(temp_lo)
167+
FROM weather
168+
WHERE city LIKE 'S%'
169+
GROUP BY city;
170+
171+
-- Another way is the FILTER clause, which operates per-aggregate:
172+
SELECT city, count(*) FILTER (WHERE temp_lo < 45), max(temp_lo)
173+
FROM weather
174+
GROUP BY city;
175+
159176

160177
-----------------------------
161178
-- Updates:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp