我有從表單中收集的數據。並具有「擺動」的數據,所以它看起來是這樣的:在幾列之間顯示最大值的列名稱
COUNTY | denver | seattle | new_york | dallas | san fran
-----------+---------+-----------+----------+----------+---------
ada | 3 | 14 | 0 | 0 | 0
slc | 10 | 0 | 0 | 0 | 9
canyon | 0 | 5 | 0 | 0 | 0
washington | 0 | 0 | 11 | 0 | 0
bonner | 0 | 0 | 0 | 2 | 0
(這是用case語句來完成,交叉表是不允許我使用環境:cartodb)
我現在需要一個列用最大值列出CITY
。例如:
COUNTY | CITY | denver | seattle | new_york | dallas | san fran
-----------+----------+---------+-----------+----------+----------+---------
ada | seattle | 3 | 14 | 0 | 0 | 0
slc | denver | 10 | 0 | 0 | 0 | 9
canyon | seattle | 0 | 5 | 0 | 0 | 0
washington | new_york | 0 | 0 | 11 | 0 | 0
bonner | dallas | 0 | 0 | 0 | 2 | 0
感謝您的回覆。我想知道是否可以在一個查詢中做到這一點。例如,下面是我用得到我上面的數據寫入第一表例如查詢,whick擺動數據:
SELECT counties.name, counties.state, counties.the_geom,
count(case when fandom_survey_one.favorite_team = 'Arizona Cardinals' then 'ari' end) ari,
count(case when fandom_survey_one.favorite_team = 'Atlanta Falcons' then 'atl' end) atl,
count(case when fandom_survey_one.favorite_team = 'Baltimore Ravens' then 'bal' end) bal,
count(case when fandom_survey_one.favorite_team = 'Buffalo Bills' then 'buf' end) buf,
count(case when fandom_survey_one.favorite_team = 'Carolina
FROM fandom_survey_one, counties
WHERE ST_Intersects(fandom_survey_one.the_geom, counties.the_geom)
group by counties.name, counties.state, counties.the_geom
order by counties.name, counties.state
我不知道是否有以納入戈登或者歐文提供這個答案的方式第一個查詢可以在一個查詢中完成。謝謝。
您可以發佈您用來創建第一個結果的查詢嗎? – paqogomez 2014-11-21 17:30:34
(i)您是否仍然擁有上表中的數據庫中可訪問的原始數據(不支持)?什麼是表結構? (ii)如果不止一個城市具有某個縣的最大價值,會發生什麼? – Abecee 2014-11-21 18:58:28
我發佈了上面的原始查詢(這是爲我創建的樞軸)。我的數據是從谷歌形式進來的,這就是爲什麼我要擺脫它。如果有更多的城市具有相同的最大值,我希望包括這兩個,但願意只選擇第一個。 – user30832 2014-11-23 21:45:41