从appengine数据存储区使用Group By获取记录

时间:2010-04-16 14:09:05

标签: python google-app-engine

我正在尝试这样的事情:

result = db.GqlQuery("SELECT * FROM myDataMode COUNT(Employee) GROUP BY(Department) WHERE Salary > :1"10000)

我收到了错误:

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

任何人都可以帮助我。

2 个答案:

答案 0 :(得分:5)

GQL不是SQL。它没有COUNT()GROUP BY()。有关详细信息,请参阅GQL reference

答案 1 :(得分:1)

由于GQL没有COUNTGROUP BY功能。 所以我为它设计了一个解决方案:

result = db.GqlQuery( SELECT * form Employee)

从结果中创建一个具有唯一Departments的数组:

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"