我有从表单中收集的数据。并具有“摆动”的数据,所以它看起来是这样的:在几列之间显示最大值的列名称
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