我有一个名为WorkoutTable的表: http://postimg.org/image/8rw5t7u0n/
我有一个名为DateofWorkout的表: http://postimg.org/image/9tqjkyszv/be35531c/
在DateofWorkout表中,我有一个名为'workout_id_2'的列,它引用了我的WorkoutTable中名为'workout_id'的列。
基本上我想制作一个显示DateofWorkoutTable但不是'workout_id_2'的表格,我想让它显示锻炼的名称。
根据我的模拟,以下SQL代码执行此操作:
SELECT date_of_workout_id,date_of_workout,workout_name FROM WorkoutTable INNER JOIN DateofWorkout ON WorkoutTable.workout_id = DateofWorkout.workout_id_2 ORDER BY date_of_workout_id
根据我的模拟,INNER JOIN和LEFT JOIN都可以使用。
此外,我正试图在我的android项目中读出我的实际数据库:
public String test(String WorkoutSelectedNameInfo) {
// TODO Auto-generated method stub
String EquivofWorkoutID = "";
String dateofworkoutid = "";
String dateofworkout = "";
open();
ourDatabase = ourhelper.getReadableDatabase();
Cursor c = ourDatabase.rawQuery("SELECT date_of_workout_id, date_of_workout,
workout_name FROM WorkoutTable LEFT JOIN DateofWorkout ON WorkoutTable.workout_id =
DateofWorkout.workout_id_2 ORDER BY date_of_workout_id", null);
if (c.moveToFirst()) {
do {
EquivofWorkoutID = EquivofWorkoutID + c.getString(c.getColumnIndex(STRING_WORKOUT))+ "\n" ;
dateofworkoutid = dateofworkoutid + c.getString(c.getColumnIndex(KEY_DATE_OF_WORKOUT))+ "\n" ;
dateofworkout = dateofworkout + c.getString(c.getColumnIndex(KEY_DATE))+ "\n" ;
} while (c.moveToNext());
}
c.close();
ourDatabase.close();
System.out.println(EquivofWorkoutID);
System.out.println("the id date of the workout is" + dateofworkoutid );
System.out.println("the date of the workout is" + dateofworkout );
return EquivofWorkoutID;
}
正如您所见,我设置了我的代码以输出EquivofWorkoutID,dateofworkoutid和dateofworkout的值。但是,在执行时,'EquivofWorkoutID'实际上只显示WorkoutTable的STRING_WORKOUT列中存在的任何内容,而不是JOINED表。此外,dateofworkoutid和dateofworkout保持为“null”,表示游标尚未实现INNER JOIN语句。如何使用图像中显示的SQL查询读出显示的信息?提前谢谢!