ORMLite orderBy多列不起作用

时间:2016-05-23 17:48:55

标签: java android sql sql-order-by ormlite

我在订购我正在通过ORMLite查询的对象列表时出现问题,我希望通过2个单独的列进行排序。我想按优先顺序排列最低,计数最高。然而,似乎查询只接受我设置的最后一个orderBy而不是两者。例如,这里有两个查询及其结果:

QueryBuilder<CategoryData, Integer> queryBuilder4 = dao.queryBuilder();
queryBuilder4.orderBy(CategoryData.FACE_COUNT_COLUMN_NAME, false);
queryBuilder4.orderBy(CategoryData.PRIORITY_COLUMN_NAME, true);
Log.d(TAG, "4 Query returns:"+ queryBuilder4.query().toString());

它的输出:

name=Blues, db=158, count=3, priority=1, firstLookDbID=6
name=Greens, db=165, count=3, priority=8, firstLookDbID=9
name=Blacks, db=157, count=1, priority=0, firstLookDbID=2,...

第二个代码块:

QueryBuilder<CategoryData, Integer> queryBuilder5 = dao.queryBuilder();
queryBuilder5.orderBy(CategoryData.PRIORITY_COLUMN_NAME, true);
queryBuilder5.orderBy(CategoryData.FACE_COUNT_COLUMN_NAME, false);
Log.d(TAG, "5 Query returns:"+ queryBuilder5.query().toString());

它的输出:

name=Blacks, db=157, count=1, priority=0, firstLookDbID=2
name=Blues, db=158, count=3, priority=1, firstLookDbID=6
...
name=Greens, db=165, count=3, priority=8, firstLookDbID=9...

请注意,两个查询之间的唯一区别是我下订单的顺序。然而,他们给了我2个不同的有序集。

2 个答案:

答案 0 :(得分:0)

您的第一个查询(queryBuilder4)以后代方式按FACE_COUNT_COLUMN_NAME对结果进行排序,如果存在相同的值,在这种情况下为“count = 3”,则查询使用PRIORITY_COLUMN_NAME按顺序在“优先级”中对结果进行排序方式。

第二个查询(queryBuilder5)以优先方式按PRIORITY_COLUMN_NAME排序结果,但在“优先级”中不存在相同的值,因此FACE_COUNT_COLUMN_NAME&#34;顺序为#34;被忽略,结果与第一个查询不同。

答案 1 :(得分:0)

  

请注意,两个查询之间的唯一区别是我下订单的顺序。然而,他们给了我2个不同的有序集。

右。这是预期的行为。在SQL中,remote: [INFO] Copying guava-12.0.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/guava-12.0.jar remote: [INFO] Copying jersey-server-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-server-2.22.2.jar remote: [INFO] Copying javassist-3.18.1-GA.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/javassist-3.18.1-GA.jar remote: [INFO] Copying mimepull-1.6.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/mimepull-1.6.jar remote: [INFO] Copying jsr305-1.3.9.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jsr305-1.3.9.jar remote: [INFO] Copying commons-beanutils-1.8.3.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/commons-beanutils-1.8.3.jar remote: [INFO] Copying hk2-locator-2.4.0-b34.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/hk2-locator-2.4.0-b34.jar remote: [INFO] Copying soda-api-java-0.9.12.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/soda-api-java-0.9.12.jar remote: [INFO] Copying jersey-container-servlet-core-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-container-servlet-core-2.22.2.jar remote: [INFO] Copying jersey-common-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-common-2.22.2.jar remote: [INFO] Copying jetty-security-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-security-9.0.6.v20130930.jar remote: [INFO] Copying jersey-bundle-1.9.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-bundle-1.9.1.jar remote: [INFO] Copying jackson-jaxrs-1.9.13.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jackson-jaxrs-1.9.13.jar remote: [INFO] Copying joda-time-2.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/joda-time-2.1.jar remote: [INFO] Copying commons-logging-1.1.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/commons-logging-1.1.1.jar remote: [INFO] Copying jersey-client-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-client-2.22.2.jar remote: [INFO] Copying validation-api-1.1.0.Final.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/validation-api-1.1.0.Final.jar remote: [INFO] Copying jetty-webapp-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-webapp-9.0.6.v20130930.jar remote: [INFO] Copying jersey-container-servlet-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-container-servlet-2.22.2.jar remote: [INFO] Copying osgi-resource-locator-1.0.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/osgi-resource-locator-1.0.1.jar remote: [INFO] Copying jackson-xc-1.9.13.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jackson-xc-1.9.13.jar remote: [INFO] Copying jersey-guava-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-guava-2.22.2.jar remote: [INFO] Copying jackson-mapper-asl-1.9.13.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jackson-mapper-asl-1.9.13.jar remote: [INFO] Copying javax.inject-2.4.0-b34.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/javax.inject-2.4.0-b34.jar remote: [INFO] Copying opencsv-2.0.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/opencsv-2.0.jar remote: [INFO] Copying jetty-server-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-server-9.0.6.v20130930.jar remote: [INFO] Copying jetty-io-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-io-9.0.6.v20130930.jar remote: [INFO] Copying hk2-api-2.4.0-b34.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/hk2-api-2.4.0-b34.jar remote: [INFO] Copying jetty-util-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-util-9.0.6.v20130930.jar remote: [INFO] Copying aopalliance-repackaged-2.4.0-b34.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/aopalliance-repackaged-2.4.0-b34.jar remote: [INFO] Copying jetty-http-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-http-9.0.6.v20130930.jar remote: [INFO] Copying jackson-core-asl-1.9.13.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jackson-core-asl-1.9.13.jar remote: [INFO] Copying jersey-multipart-1.9.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-multipart-1.9.1.jar remote: [INFO] Copying hk2-utils-2.4.0-b34.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/hk2-utils-2.4.0-b34.jar remote: [INFO] Copying jetty-xml-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-xml-9.0.6.v20130930.jar remote: [INFO] Copying jersey-media-json-jackson1-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-media-json-jackson1-2.22.2.jar remote: [INFO] Copying commons-lang3-3.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/commons-lang3-3.1.jar remote: [INFO] Copying jsr311-api-1.1.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jsr311-api-1.1.1.jar remote: [INFO] Copying jersey-media-jaxb-2.22.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-media-jaxb-2.22.2.jar remote: [INFO] Copying jersey-core-1.9.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jersey-core-1.9.1.jar remote: [INFO] Copying jetty-servlet-9.0.6.v20130930.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/jetty-servlet-9.0.6.v20130930.jar remote: [INFO] Copying commons-io-1.3.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/commons-io-1.3.2.jar remote: [INFO] Copying javax.annotation-api-1.2.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/javax.annotation-api-1.2.jar remote: [INFO] Copying javax.servlet-3.0.0.v201112011016.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/javax.servlet-3.0.0.v201112011016.jar remote: [INFO] Copying javax.ws.rs-api-2.0.1.jar to /tmp/build_4959660edbd9bc2e826e322947728edc/target/dependency/javax.ws.rs-api-2.0.1.jar 子句按特定顺序处理。引用QueryBuilder.orderby(...) javadocs强调:

  

将“ORDER BY”子句添加到SQL查询语句中。这可以被多次调用以添加额外的“ORDER BY”子句。 先前使用的是

因此,在第一个实例中,clc clear all W=cell(16,1); for g=1:16; temp = zeros(3,3); for m=1:3 for n=1:3 temp (m,n) = exp((2*pi*1i*m/4)* n+g/16); end end W{g} = temp; end 首先按降序排序。如果计数相等,则ORDER BY按升序排序。在第二个中,优先级首先按升序排序。如果优先级相等,则计数按降序排列。