2012-08-06 34 views
0

謝謝大家的回答: @ODI - 我的最終需求是我想解僱上述查詢並首先查找相關國家併爲它着色,然後(現在不是imp)就是在地圖上顯示這個數字。 我正在嘗試你提到的建議。Google fusion table - 在融合表中處理「group by」和「count(col_name)」函數

@ user1224571 - 謝謝你。

@Eric - 其實你查詢發佈沒有工作。請在下面找到工作代碼。如果你添加group by子句它不會工作。

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
<meta charset="UTF-8"> 

<title>Fusion Tables Layer Example: Basic Fusion Tables Layer</title> 

<link href="http://code.google.com/apis/fusiontables/docs/samples/style/default.css" 
    rel="stylesheet" type="text/css"> 

<script type="text/javascript" 
    src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 

<script type="text/javascript"> 
var map; 
    function initialize() { 
    map = new google.maps.Map(document.getElementById('map-canvas'), { 
     center: new google.maps.LatLng(44.0718, -2.768555), 
     zoom: 2, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    var layer = new google.maps.FusionTablesLayer({ 
     query: { 
      select: 'masterNarrative, (count())', 
      from: '1EsjL3dUyez6R8bXlJVtrL8Zq3esRsaoxcamKoVM', 
      where : "masterNarrative IN ('Pharaoh','Badr')"}, 
     styles: [{ 
      polygonOptions: { 
      fillColor: '#00FF00', 
      fillOpacity: 0.5 
      } 
     }] 
     //map: map 
    }); 
    layer.setMap(map); 
    } 


    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
</head> 
<body> 
<div id="map-canvas"></div> 
</body> 
</html> 
+0

我猜你想要顯示的查詢文本,而不是在地圖上,右側的結果呢?如果是這樣,您不應該使用FusionTablesLayer,而應該查看[SQL參考](https://developers.google.com/fusiontables/docs/v1/sql-reference),也可以使用[gapi-client ](http://code.google.com/p/google-api-javascript-client/)。請參閱[此答案爲客戶端的示例用法](http://stackoverflow.com/a/11747872/549755)。 – Odi 2012-08-06 16:29:29

+0

請在上面找到我的回覆作爲主要問題。我無法發佈我自己的回覆以獲取某些堆棧溢出限制 – ravi 2012-08-06 21:34:11

+0

如果要使用FusionTablesLayer在地圖上顯示數據,則必須在選擇部分中添加位置列(請參見[FusionTablesLayer文檔](https://developers.google。 com/maps/documentation/javascript/layers#FusionTablesConstructor)。在你的情況下,這可能是「幾何」列。 – Odi 2012-08-07 05:11:41

回答

1

根據SQL reference,count語法只是count(),而不是count(column_name)。

+0

請在上面找到我的回覆作爲主要問題。我無法發佈我自己的答覆一些stackoverflow限制 – ravi 2012-08-06 21:18:33

0

user1224571是正確的。

嘗試:

query: { 
    select: 'master_narrative_name, (count())', 
    from: '1hFPiPmQilakQ4zESVCJqq9ENmeo5e_EJXy_Usy8', 
    where : "master_narrative_name IN ('Pharaoh','Badr')" GROUP BY master_narrative_name}, 
+0

請找到我的答覆上面的主要問題。我無法發佈我自己的答覆一些stackoverflow限制 – ravi 2012-08-06 21:37:04

+0

我的例子中有一個相當明顯的語法錯誤。雙引號應該在行尾。我的經驗是,需要GROUP BY才能計數。 – 2012-08-08 01:28:16

+0

感謝Eric的回覆,但這件事不起作用。我修改瞭如下的where子句,但它不起作用。其中:「masterNarrative IN('Pharaoh','Badr')GROUP BY masterNarrative」 – ravi 2012-08-08 05:13:15