开发者

Rounding in Google Query Language

I'd like to implement a series of queries with rounding in Google Query Langu开发者_JAVA百科age, 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


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

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


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

"select age format age '0'"

See Google Query Language Reference - Format.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜