私は、最高のレベルとあなたが完了したレベルの数を取得する小さなゲームを構築しています。これは、質問の半分以上が正解です。これをチェックするクエリがありますが、質問テーブルを統合する方法がわからない問題があります。ユーザーが質問に答えようとしなかった場合、回答テーブルに行は書き込まれません。したがって、実際には各レベルの回答表の行数と比較されます。これを統合する方法についてのアイデアはありますか? 実際には (count(*)/2)
Cursor c = myDataBase
.rawQuery(
"select level, (select count(*) from ( select level from answers group by level having sum (answercorrect) >= (count(*)/2) ) answers ) completedlevels, "
+ "from answers "
+ "group by level "
+ "order by sum (score) desc ", null);
私はこれを試しましたが、うまくいきませんでした:
Cursor c = myDataBase
.rawQuery(
"select level, (select count(*) from ( select level from questions group by level having sum (answercorrect) >= ((select count(*)/2 from questions group by level) ) answers ) completedlevels, "
+ "from answers "
+ "group by level "
+ "order by sum (score) desc ", null);
編集 テーブル構造は次のとおりです。
questions table
id level question
1 1 question1level1
2 1 question2level1
...
30 1 question30level1
31 2 question1level2
32 2 question2level2
...
70 2 question40level2
71
...
//注: レベルごとに異なる数の問題を設定できます
回答表
id question_id player answercorrect score attempts
1 5 1 1 1000 1
2 10 1 1 900 1
3 7 2 0 700 3
4 10 2 0 500 3
5 13 2 1 100 1
6 8 1 1 800 2
...