如果所选列中只有空值,如何使用toDate查询Google电子表格

时间:2016-04-04 08:04:12

标签: google-visualization

我想使用toDate查询的列只包含空值,查询失败则不执行。

查询:选择*其中toDate(A)> =' 2016-01-01'。

https://docs.google.com/spreadsheets/d/19olM1pEF5qQvvKhwSH3d_X4w2DVfOWDwDtZKNFlMY3w/edit#gid=0

我该怎么办?

注意:即使给定列中只有一个条目,查询也能正常工作。

1 个答案:

答案 0 :(得分:0)

不了解toDate ...

但是要将值转换为日期,只需在值前加上“date”一词。

即。 - > date '2016-01-01'

参见以下示例...

google.charts.load('current', {
  callback: drawVisualization,
  packages: ['table']
});

function drawVisualization() {
  var query = new google.visualization.Query(
    'https://docs.google.com/spreadsheets/d/19olM1pEF5qQvvKhwSH3d_X4w2DVfOWDwDtZKNFlMY3w/edit#gid=0'
  );

  query.setQuery("select * where A >= date '2016-01-01'");
  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }

  var data = response.getDataTable();

  if (data.getNumberOfRows() === 0) {
    data.setColumnLabel(0, 'Date');
    data.setColumnLabel(1, 'Goal');
    data.addRow([null, 'Nothing found']);
  }

  var visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, {});
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="table"></div>