5

I'd like to implement a series of queries with rounding in Google Query Language, such as:

select round(age,-1), count(id) group by round(age,-1)

or any combination of int/floor/etc.

select int(age/10)*10, count(id) group by int(age/10)*10

Is there any way to do that? I suspect no, as the list of scalar functions in GQL is very limited, but do wonder if there's a workaround.

http://code.google.com/apis/chart/interactive/docs/querylanguage.html#scalar_functions

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
prototype
  • 7,249
  • 15
  • 60
  • 94

3 Answers3

3

Add a format at the end of the query, for example:

"select age format age '0'"

See Google Query Language Reference - Format.

Janine White
  • 439
  • 5
  • 14
3

No, I dont think we can do rounding in GQL...

The link that you have shown is not for google app engine...

SRK
  • 1,020
  • 1
  • 9
  • 11
2

Although there are no explicit round or floor functions, one can implement them using the modulus operator % and the fact that value % 1 returns the decimal part of value. So value - value % 1 is equivalent to floor(value), at least for positive values. More generally value - value % k should be equivalent to floor(value / k) * k.

In your case, your query should look like:

select age - age % 10, count(id) group by age - age % 10
Pedro Pedruzzi
  • 799
  • 7
  • 12