我认为这个问题在其他地方没有被问到,但如果您不这么认为,请随时告诉我。
我有两张桌子:
Table A (Transactions)
id ¦ player_id ¦ t_out ¦ team_id
Table B (Players)
id ¦ club_id
我需要做的是计算表A中具有特定表B.club_id的条目数,而表A.t_out为空,表A.team_id是特定值。
注意事项: 表A.player_id参见表B.id
我已经浏览了MySql帮助文档,但似乎无法将它拼凑在一起。
答案 0 :(得分:0)
这应该适合你:
package com.example.healthcare;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
public class StoredValuesDBHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "StoredValues.db";
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
public static abstract class ValueEntry implements BaseColumns {
public static final String TABLE_NAME = "storedvalue";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_CONTENT = "content";
}
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + ValueEntry.TABLE_NAME + " (" +
ValueEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE + COMMA_SEP +
ValueEntry.COLUMN_NAME_CONTENT + TEXT_TYPE + COMMA_SEP +")";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + ValueEntry.TABLE_NAME;
public StoredValuesDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This database is only a cache for online data, so its upgrade policy is
// to simply to discard the data and start over
db.execSQL(SQL_DELETE_ENTRIES);
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}