0

数据库结构:

public final class ManufacturersColumns implements MyStyleBaseColumns {
public static final String ALIAS           = "alias";
public static final String MANUFACTURER_ID = "manufacturer_id";
public static final String NAME            = "name";

public static final String TABLE_NAME = "manufacturers";

public static final String CREATE_TABLE =
        "CREATE TABLE " + TABLE_NAME + "( "
                + _ID             + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + ALIAS           + " TEXT, "
                + DATE_DELETED    + " DATE, "
                + DATE_CREATED    + " DATE, "
                + DATE_MODIFIED   + " DATE, "
                + MANUFACTURER_ID + " TEXT, "
                + NAME            + " TEXT "
        + ");";}






public final class ManufacturersUserCreatedColumns implements MyStyleBaseColumns {
    public static final String MANUFACTURER_ID = "manufacturer_id";
    public static final String NAME            = "name";

    public static final String TABLE_NAME = "manufacturers_user_created";

    public static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + "( "
                    + _ID             + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + MANUFACTURER_ID + " TEXT, "
                    + NAME            + " TEXT, "
                    + DATE_CREATED    + " DATE, "
                    + DATE_MODIFIED   + " DATE, "
                    + DATE_DELETED    + " DATE, "
                    + SYNC_FLAG       + " NUMERIC " 
            + ");";
}

现在我们使用下面提到的查询来列出名称:

<string name="kGetAllManufacturers"><![CDATA["SELECT _id, manufacturer_id, name, alias, usergen FROM (SELECT _id, manufacturer_id, name, alias, 0 AS usergen FROM manufacturers UNION SELECT _id, manufacturer_id, name, '' AS alias, 1 AS usergen FROM manufacturers_user_created) main ORDER BY lower(name) ASC"]]>

要求是:

需要更改上面经常选择的列表名称的查询。

提前致谢。

4

1 回答 1

0

最后我通过使用这个查询解决了我的问题。

<string name="kGetAllManufacturers"><![CDATA["SELECT _id, man_id, name, alias, usergen, count(man_id) as amount from (SELECT c._id as _id, c.manufacturer_id as man_id, m.name as name, m.alias as alias, 0 AS usergen FROM clothes c INNER JOIN manufacturers m ON m.manufacturer_id = c.manufacturer_id UNION all SELECT c._id as _id, c.manufacturer_id as man_id, ucm.name as name, '' AS alias, 1 AS usergen FROM clothes c INNER JOIN manufacturers_user_created ucm ON ucm.manufacturer_id = c.manufacturer_id UNION SELECT _id, manufacturer_id, name, alias, 0 AS usergen FROM manufacturers UNION SELECT _id, manufacturer_id, name, '' AS alias, 1 AS usergen FROM manufacturers_user_created ) main GROUP BY man_id, name ORDER BY COUNT(man_id) desc"]]></string>
于 2013-10-08T04:32:25.923 回答