获取sqlite android中的平均数据

时间:2013-05-06 04:58:01

标签: android sql sqlite

我希望执行以下查询,

  String selectQuery = "SELECT  max(score),name FROM " + TABLE_SCORE
                        +" group by name";

我将输出作为随机值。实际上我希望数据从最大值到最小值。请告诉我,如何编写查询。

2 个答案:

答案 0 :(得分:2)

  

实际上我希望数据从最大值到最小值

你的意思是按最大值到最小值的顺序?试试这个:

  SELECT SUM(score), name 
    FROM MyTable
GROUP BY name
ORDER BY SUM(score) DESC;

See this SQLFiddle

所以你的查询应该是这样的:

String selectQuery = "SELECT SUM(score), name FROM " + TABLE_SCORE
                        +" GROUP BY name ORDER BY SUM(score) DESC";

答案 1 :(得分:0)

String selectQuery = "SELECT  score, name FROM " + TABLE_SCORE
                        +" order by score, group by name";

这将根据分数(分数的升序)给出记录。