我想从两个表中获取所有数据,并将其转换为StringBuffer,但是查询有问题。我不知道该怎么称呼。

该方法将显示由用户创建的培训计划。该计划将有两种。例如,在FBW_TABLE_SET_A_CHEST中,用户选择了名为“挤压杠铃”的练习,而在FBW_TABLE_SET_B_CHEST中,用户选择了名为“挤压哑铃”的练习。

这是表的调用方式

private static final String FBW_TABLE_NAME_SET_A = "FbwSetA";
private static final String FBW_TABLE_SET_A_CALF = "calfExerciseSetA";
private static final String FBW_TABLE_SET_A_LEGS = "legsExerciseSetA";
private static final String FBW_TABLE_SET_A_BACK = "backExerciseSetA";
private static final String FBW_TABLE_SET_A_SHOULDERS = "shouldersExerciseSetA";
private static final String FBW_TABLE_SET_A_BICEPS = "bicepsExerciseSetA";
private static final String FBW_TABLE_SET_A_TRICEPS = "tricepsExerciseSetA";
private static final String FBW_TABLE_SET_A_CHEST = "chestExerciseSetA";
private static final String FBW_TABLE_SET_A_ABS = "absExerciseSetA";
private static final String FBW_TABLE_SET_A_FOREARM = "forearmExerciseSetA";

private static final String FBW_TABLE_NAME_SET_B = "FbwSetB";
private static final String FBW_TABLE_SET_B_CALF = "calfExerciseSetB";
private static final String FBW_TABLE_SET_B_LEGS = "legsExerciseSetB";
private static final String FBW_TABLE_SET_B_BACK = "backExerciseSetB";
private static final String FBW_TABLE_SET_B_SHOULDERS = "shouldersExerciseSetB";
private static final String FBW_TABLE_SET_B_BICEPS = "bicepsExerciseSetB";
private static final String FBW_TABLE_SET_B_TRICEPS = "tricepsExerciseSetB";
private static final String FBW_TABLE_SET_B_CHEST = "chestExerciseSetB";
private static final String FBW_TABLE_SET_B_ABS = "absExerciseSetB";
private static final String FBW_TABLE_SET_B_FOREARM = "forearmExerciseSetB";


这是我通过db.execSQL(..)“创建”它的方式

db.execSQL("create table " + FBW_TABLE_NAME_SET_A + " (ID INTEGER PRIMARY KEY AUTOINCREMENT," + FBW_TABLE_SET_A_CALF + " TEXT," + FBW_TABLE_SET_A_LEGS + " TEXT," + FBW_TABLE_SET_A_BACK + " TEXT," + FBW_TABLE_SET_A_SHOULDERS + " TEXT," + FBW_TABLE_SET_A_BICEPS + " TEXT," + FBW_TABLE_SET_A_TRICEPS + " TEXT," + FBW_TABLE_SET_A_CHEST + " TEXT," + FBW_TABLE_SET_A_ABS + " TEXT," + FBW_TABLE_SET_A_FOREARM + " TEXT)");
    db.execSQL("create table " + FBW_TABLE_NAME_SET_B + " (ID INTEGER PRIMARY KEY AUTOINCREMENT," + FBW_TABLE_SET_B_CALF + " TEXT," + FBW_TABLE_SET_B_LEGS + " TEXT," + FBW_TABLE_SET_B_BACK + " TEXT," + FBW_TABLE_SET_B_SHOULDERS + " TEXT," + FBW_TABLE_SET_B_BICEPS + " TEXT," + FBW_TABLE_SET_B_TRICEPS + " TEXT," + FBW_TABLE_SET_B_CHEST + " TEXT," + FBW_TABLE_SET_B_ABS + " TEXT," + FBW_TABLE_SET_B_FOREARM + " TEXT)");


总而言之:该方法应该从两个表中获取所有数据,然后强制转换为StringBuffer并显示由他的培训计划创建的用户。

最佳答案

使用UNION复合运算符。

SQL代码是这样的:

SELECT col1, col2 from table1 UNION SELECT col1, col2 from table2

关于java - 我如何从查询中的两个表中获取数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54736421/

10-09 00:53