android中的groupby

android中的groupby,android,Android,当我在android中使用GroupBy时,代码中有什么问题。请在sqlite中测试此代码: public void getPlayerName_OrderBy(int First_TeamID) { int Match_ID = get_MatchID(); int matchId; int teamID; int PlayerID; String Name; if(Player_SD

当我在android中使用GroupBy时,代码中有什么问题。请在sqlite中测试此代码:

public void getPlayerName_OrderBy(int First_TeamID)
 {
       int Match_ID = get_MatchID();         

       int matchId;
       int teamID;
       int PlayerID;
       String Name;
        if(Player_SD != null)
            Player_SD.clear();

               String selectQuery = "SELECT "+ STStrikerPlayerName+", count +"("+STStrikerPlayerName+")" +" FROM " +TABLE_SCORE+" where "+ STMatchID +" = '"+ Match_ID +"'"+" AND "      +STFristTeamID + "= '"+First_TeamID+"'"+" GROUP BY "+STStrikerPlayerName;

       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery(selectQuery, null);

       if (cursor.moveToFirst()) {
            do {
                Player_score_details psd = new Player_score_details();

                matchId = Integer.parseInt(cursor.getString(0));    
                teamID = Integer.parseInt(cursor.getString(1));                                     


                PlayerID = Integer.parseInt(cursor.getString(3));                   


                Name = cursor.getString(20); 



            } while (cursor.moveToNext());
        }

        db.close();    


 }
您可以使用以下命令

/**
     * Selects records from table
     * 
     * @param table
     *            = name of table
     * @param columns
     *            = String[] for columns
     * @param where
     *            = WHERE condition
     * @param whereargs
     *            = arguments if where parameter is in prepared statement format
     * @param groupby
     *            = GROUP BY column(s)
     * @param having
     *            = HAVING condition
     * @param orderby
     *            = ORDER BY column witrh asc, desc specification
     * @return
     */
    public List<Object[]> select(String table, String columns[], String where,
            String whereargs[], String groupby, String having, String orderby)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.query(table, columns, where, whereargs,
                groupby, having, orderby);      
        List<Object[]> list = parseCursorToList(cursor);
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
        return list;
    }
您可以使用以下命令

/**
     * Selects records from table
     * 
     * @param table
     *            = name of table
     * @param columns
     *            = String[] for columns
     * @param where
     *            = WHERE condition
     * @param whereargs
     *            = arguments if where parameter is in prepared statement format
     * @param groupby
     *            = GROUP BY column(s)
     * @param having
     *            = HAVING condition
     * @param orderby
     *            = ORDER BY column witrh asc, desc specification
     * @return
     */
    public List<Object[]> select(String table, String columns[], String where,
            String whereargs[], String groupby, String having, String orderby)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.query(table, columns, where, whereargs,
                groupby, having, orderby);      
        List<Object[]> list = parseCursorToList(cursor);
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
        return list;
    }

这是主要的解决方案

public void getPlayerName\u OrderByint First\u TeamID { int Match_ID=get_MatchID

       int matchId;
       int teamID;
       int PlayerID;
       String StrikerName;
        if(Player_SD != null)
            Player_SD.clear();

       String selectQuery = "SELECT "+STMatchID+","+ STFristTeamID+","+ STStrikerPlayerID +","+ STStrikerPlayerName+", count "+"("+STStrikerPlayerName+")"+" FROM " 
                                     +TABLE_SCORE+" where "+ STMatchID +" = '"+ Match_ID +"'"+" AND "
                                     +STFristTeamID + "= '"+First_TeamID+"'"+" GROUP BY "+STStrikerPlayerName;

       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery(selectQuery, null);

       if (cursor.moveToFirst()) {
            do {
                Player_score_details psd = new Player_score_details();

                matchId = cursor.getInt(cursor.getColumnIndex(STMatchID));
                psd.MTMID = cursor.getInt(cursor.getColumnIndex(STMatchID));

                teamID = cursor.getInt(cursor.getColumnIndex(STFristTeamID));                               
                psd.MTID = cursor.getInt(cursor.getColumnIndex(STFristTeamID));  

                PlayerID = cursor.getInt(cursor.getColumnIndex(STStrikerPlayerID));  
                psd.MTPID = cursor.getInt(cursor.getColumnIndex(STStrikerPlayerID));  

                StrikerName = cursor.getString(cursor.getColumnIndex(STStrikerPlayerName));  
                psd.PlayerName = cursor.getString(cursor.getColumnIndex(STStrikerPlayerName)); 

                Player_SD.add(psd);

            } while (cursor.moveToNext());
        }

        db.close();
}

这是主要的解决方案

public void getPlayerName\u OrderByint First\u TeamID { int Match_ID=get_MatchID

       int matchId;
       int teamID;
       int PlayerID;
       String StrikerName;
        if(Player_SD != null)
            Player_SD.clear();

       String selectQuery = "SELECT "+STMatchID+","+ STFristTeamID+","+ STStrikerPlayerID +","+ STStrikerPlayerName+", count "+"("+STStrikerPlayerName+")"+" FROM " 
                                     +TABLE_SCORE+" where "+ STMatchID +" = '"+ Match_ID +"'"+" AND "
                                     +STFristTeamID + "= '"+First_TeamID+"'"+" GROUP BY "+STStrikerPlayerName;

       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery(selectQuery, null);

       if (cursor.moveToFirst()) {
            do {
                Player_score_details psd = new Player_score_details();

                matchId = cursor.getInt(cursor.getColumnIndex(STMatchID));
                psd.MTMID = cursor.getInt(cursor.getColumnIndex(STMatchID));

                teamID = cursor.getInt(cursor.getColumnIndex(STFristTeamID));                               
                psd.MTID = cursor.getInt(cursor.getColumnIndex(STFristTeamID));  

                PlayerID = cursor.getInt(cursor.getColumnIndex(STStrikerPlayerID));  
                psd.MTPID = cursor.getInt(cursor.getColumnIndex(STStrikerPlayerID));  

                StrikerName = cursor.getString(cursor.getColumnIndex(STStrikerPlayerName));  
                psd.PlayerName = cursor.getString(cursor.getColumnIndex(STStrikerPlayerName)); 

                Player_SD.add(psd);

            } while (cursor.moveToNext());
        }

        db.close();
}

你应该使用rawQuery的第二个参数…这将有助于清理你的语句…查询很混乱-和+都不正常。嗯,很多事情都可能出错。首先:StrikerPlayerName、TABLE_SCORE、STMatchID、STFristTeamID的内容是什么?然后告诉我们你从代码中得到的异常或行为。最后添加一个line Log.dTAG,在selectQueryinitialization之后立即选择查询,并告诉我们您得到了什么。您应该使用rawQuery的第二个参数…这将有助于清理您的语句…查询非常混乱-和+都不正常。嗯,很多事情都可能出错。第一:STStrikerPlayerName、TABLE\u SCORE、STMatchID、s的内容是什么TFristTeamID?然后告诉我们您从代码中得到了哪些异常或行为。最后添加一行Log.dTAG,在selectQueryinitialization之后立即选择Query,并告诉我们您得到了什么。