Fetch records using Group By from appengine datast

2019-07-26 16:53发布

I am trying something like this:

result = 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.

2条回答
我想做一个坏孩纸
2楼-- · 2019-07-26 16:54

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"
查看更多
Luminary・发光体
3楼-- · 2019-07-26 17:12

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

查看更多
登录 后发表回答