开发者

Fetch records using Group By from appengine datastore

I am trying something like this:

result开发者_Go百科 = db.GqlQuery("SELECT * FROM myDataMode COUNT(Employee) GROUP BY(Department) WHERE Salary > :1"10000)

And I am getting error :

BadQueryError: Parse Error: Expected no additional symbols at symbol count

Can any one please help me.


GQL isn't SQL. It doesn't have COUNT() or GROUP BY(). See the GQL reference for more information.


Since GQL does not have COUNT and GROUP BY function. so I designed a solution for it:

result = db.GqlQuery( SELECT * form Employee)

Make an Array which will have unique Departments from the result :

if result.Department not in array:
    array.append(result.Department)
for department in array:
    query = db.GqlQuery(SELECT * form Employee WHERE Department = :1,department)
    print "In" + department + query.count() +"Employees are working"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜