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 に答える