我正在努力在我的 android 项目中结合一些 sqlite 查询。
我通过这个调用获得了我的 ItemTable 的所有元素
String sql = "SELECT n.*, p.ParentID "
+ "FROM NameTable n, "
+ " ItemTable p "
+ "WHERE p.itemID = n.OwnerID "
+ "COLLATE NOCASE";
然后通过以下两个查询之一获取他们的每个父母:
if (aItem.parentID > 0) {
sql = "SELECT n.*, p.ParentID, f.FamilyID "
+ "FROM NameTable n, "
+ " FamilyTable f, "
+ " ItemTable p "
+ "WHERE f.FamilyID = '" + aItem.parentID + "' "
+ " AND p.ItemID = n.OwnerID "
+ " AND (p.ItemID = f.MotherID OR p.itemID = f.FatherID) "
+ " AND n.IsPrimary = 1 ";
} else {
sql = "SELECT n.*, p.ItemID, f.FamilyID "
+ "FROM NameTable n, "
+ " FamilyTable f, "
+ " ChildTable c, "
+ " ItemTable p "
+ "WHERE c.ChildID = '" + aItem.ItemID + "' "
+ " AND p.ItemID = n.OwnerID "
+ " AND c.FamilyID = f.FamilyID "
+ " AND (p.ItemID = f.MotherID OR p.ItemID = f.FatherID) "
+ " AND n.IsPrimary = 1 ";
}
有什么办法可以将这三个查询和逻辑合二为一吗?我想组合调用会更快,但我不确定如何组合它们,也不确定如果我确实组合它们如何读取行。我真的可以使用一些建议和帮助。