在SELECT语句中分配列值的更有效方法

时间:2019-04-03 14:22:51

标签: android sql android-room

在Android Room中,我有一个if (txt.SelectionStart == 0 || txt.SelectionStart == 2 || txt.SelectionStart == 4) { txt.InputType = InputTypes.ClassText | InputTypes.TextFlagCapCharacters; txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) }); } else if (txt.SelectionStart == 1 || txt.SelectionStart == 3 || txt.SelectionStart == 5) { txt.InputType = InputTypes.ClassNumber; txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) }); } 查询,其中我将列值SELECT分配给了另一列:component_category.name

经过几次试验,我通过以下查询成功完成了此操作:

component.component_category_name

但是我想知道是否有更有效的方法来减小查询的大小。

我尝试了以下操作:

@Query("SELECT component.id, rack_id, component_category_id, component.name, component.component_category_name, code, component.img_path, " +
        "       (SELECT COUNT(component.id) " +
        "        FROM component " +
        "        WHERE component.rack_id = :rackID) as count, " +
        "       (SELECT name " +
        "        FROM component_category " +
        "        WHERE component_category.id == component_category_id) as component_category_name " +
        "FROM component " +
        "INNER JOIN component_category ON component_category.id = component.component_category_id " +
        "WHERE component.rack_id == :rackID ORDER BY component.name ASC")
LiveData<List<Component>> getRackComponents(long rackID);
创建该试用的

,但该查询的结果中@Query("SELECT component.id, rack_id, component_category_id, component.name, component.component_category_name AS [component.component_category_name], code, component.img_path, " + " (SELECT COUNT(component.id) " + " FROM component " + " WHERE component.rack_id = :rackID) as count " + "FROM component " + "INNER JOIN component_category ON component_category.id = component.component_category_id " + "WHERE component.rack_id == :rackID AND component_category.id == component.component_category_id ORDER BY component.name ASC") LiveData<List<Component>> getRackComponents(long rackID); component.category_name

0 个答案:

没有答案