Displaying multiple Columns and aggregating data

Certified Lead Developer

Hi all,

I have a table with some fields (time, text, type). I want to build a query to return for every type the text that was introduced with the maximum value of time. Oracle has some restrictions and it is not simple to build the query without some tricks.

Is there a way in Appian to do this? 

TIME TEXT TYPE

--------------------------

03.05.2020 AA 2

02.04.2020 BB 2

01.04.2020 CC 1

I want a query that returns

03.05.2020 AA 2

01.04.2020 CC 1

Thanks a lot!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hi Jesusa,

    To achieve this, we need to use two query entity. One QE will return maximum value of time for type. Second QE will return the result for Text based on Time and Type filters.

    Please find out the code:

    load(
    local!maxTimeforType: a!queryEntity(
    entity: cons!PG_ENTITY_DATA,
    query: a!query(
    aggregation: a!queryAggregation(
    aggregationColumns: {
    a!queryAggregationColumn(
    field: "type",
    isGrouping: true()
    ),
    a!queryAggregationColumn(
    field: "time",
    aggregationFunction: "MAX"
    )
    }
    ),
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1
    )
    )
    ).data,
    local!typeDetails: a!queryEntity(
    entity: cons!PG_ENTITY_DATA,
    query: a!query(
    logicalExpression: a!queryLogicalExpression(
    operator: "AND",
    filters: {
    a!queryFilter(
    field: "type",
    operator: "in",
    value: tointeger(
    local!maxTimeforType.type
    )
    ),
    a!queryFilter(
    field: "time",
    operator: "in",
    value: todate(
    local!maxTimeforType.time
    )
    )
    }
    ),
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1
    )
    )
    ).data,
    local!typeDetails
    )

    Output would be this: 

    • Dictionary
        • type 1
          • text "CC"
            • time 1/4/2020
              • id 3
              • Dictionary
                  • type 2
                    • text "AA"
                      • time 3/5/2020
                        • id 1
                    Reply
                    • 0
                      Certified Lead Developer

                      Hi Jesusa,

                      To achieve this, we need to use two query entity. One QE will return maximum value of time for type. Second QE will return the result for Text based on Time and Type filters.

                      Please find out the code:

                      load(
                      local!maxTimeforType: a!queryEntity(
                      entity: cons!PG_ENTITY_DATA,
                      query: a!query(
                      aggregation: a!queryAggregation(
                      aggregationColumns: {
                      a!queryAggregationColumn(
                      field: "type",
                      isGrouping: true()
                      ),
                      a!queryAggregationColumn(
                      field: "time",
                      aggregationFunction: "MAX"
                      )
                      }
                      ),
                      pagingInfo: a!pagingInfo(
                      startIndex: 1,
                      batchSize: - 1
                      )
                      )
                      ).data,
                      local!typeDetails: a!queryEntity(
                      entity: cons!PG_ENTITY_DATA,
                      query: a!query(
                      logicalExpression: a!queryLogicalExpression(
                      operator: "AND",
                      filters: {
                      a!queryFilter(
                      field: "type",
                      operator: "in",
                      value: tointeger(
                      local!maxTimeforType.type
                      )
                      ),
                      a!queryFilter(
                      field: "time",
                      operator: "in",
                      value: todate(
                      local!maxTimeforType.time
                      )
                      )
                      }
                      ),
                      pagingInfo: a!pagingInfo(
                      startIndex: 1,
                      batchSize: - 1
                      )
                      )
                      ).data,
                      local!typeDetails
                      )

                      Output would be this: 

                      • Dictionary
                          • type 1
                            • text "CC"
                              • time 1/4/2020
                                • id 3
                                • Dictionary
                                    • type 2
                                      • text "AA"
                                        • time 3/5/2020
                                          • id 1
                                      Children