我在一个相当复杂的选择查询中的名为games._id的列上得到一个Sqlite不明确的列名,如下所示:
public Cursor getStatsByResult(String result)
{
SQLiteDatabase db = this.getReadableDatabase();
String buildSQL = "SELECT games._id AS game, games.lge, games.date, games.opp, games.ven, games.scr, " +
"SUM(CASE WHEN s_event = \"1on1\" THEN s_att END) ||\"/\"||"+
"SUM(CASE WHEN s_event = \"1on1\" THEN s_point END) AS \"1 On 1 \","+
"SUM(CASE WHEN s_event = \"MyDef\" THEN s_att END) ||\"/\"|| "+
"SUM(CASE WHEN s_event = \"MyDef\" THEN s_point END) AS \"Switching Def\","+
"SUM(CASE WHEN s_event = \"Defl\" THEN s_point END) AS Deflections "+
"FROM records "+
"INNER JOIN myplayers ON myplayers_id = s_myplayersid "+
"INNER JOIN games ON games._id = myplayers_gameid "+
"INNER JOIN games ON sessions.sessions_id = games.sessions_id AND games._id = myplayers.myplayers_game_id "+
"WHERE games.result=\""+result+"\" AND games.date BETWEEN sessions.sessions_start AND sessions.sessions_end GROUP BY "+
"games.date,games.rslt,games.opp";
return db.rawQuery(buildSQL, null);
}
为什么它仍然会显示此消息,即使我放了games._id而不仅仅是_id?
答案 0 :(得分:0)
我认为您已经尝试了别名,问题在于别名。我想是的。
String buildSQL = "SELECT games._id , games.lge, games.date, games.opp, games.ven, games.scr, " +
"SUM(CASE WHEN s_event = \"1on1\" THEN s_att END) ||\"/\"||"+
"SUM(CASE WHEN s_event = \"1on1\" THEN s_point END) AS \"1 On 1 \","+
"SUM(CASE WHEN s_event = \"MyDef\" THEN s_att END) ||\"/\"|| "+
"SUM(CASE WHEN s_event = \"MyDef\" THEN s_point END) AS \"Switching Def\","+
"SUM(CASE WHEN s_event = \"Defl\" THEN s_point END) AS Deflections "+
"FROM records game"+
"INNER JOIN myplayers ON myplayers_id = s_myplayersid "+
"INNER JOIN games ON games._id = myplayers_gameid "+
"INNER JOIN games ON sessions.sessions_id = games.sessions_id AND games._id = myplayers.myplayers_game_id "+
"WHERE games.result=\""+result+"\" AND games.date BETWEEN sessions.sessions_start AND sessions.sessions_end GROUP BY "+
"games.date,games.rslt,games.opp";
希望此查询解决您的问题。