File tree Expand file tree Collapse file tree 1 file changed +8
-17
lines changed
Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Original file line number Diff line number Diff line change @@ -270,23 +270,14 @@ SELECT percentile_cont(.5)
270270FROM us_counties_2010
271271WHERE state_us_abbreviation = ' CA' ;
272272
273- -- Second, here is a solution by GitHub user tomyfalgui
274- -- that finds both medians with one query:
275-
276- SELECT
277- percentile_cont(.5 )
278- WITHIN GROUP (ORDER BY (
279- SELECT
280- p0010001
281- WHERE state_us_abbreviation = ' CA'
282- )) AS " CA State Median" ,
283- percentile_cont(.5 )
284- WITHIN GROUP (ORDER BY (
285- SELECT p0010001
286- WHERE state_us_abbreviation = ' NY'
287- )) AS " NY State Median"
288- FROM us_counties_2010;
289-
273+ -- or both in one query
274+ SELECT state_us_abbreviation,
275+ percentile_cont(0 .5 )
276+ WITHIN GROUP (ORDER BY p0010001) AS median
277+ FROM us_counties_2010
278+ WHERE state_us_abbreviation IN (' NY' , ' CA' )
279+ GROUP BY state_us_abbreviation;
280+
290281-- Finally, this query shows the median for each state:
291282
292283SELECT state_us_abbreviation,
You can’t perform that action at this time.
0 commit comments