Query Cities w/Sort

Let's double spice it and start to get some contextual sorting underneath the MSA. In this case, lets capture the top 10 cities in descending order based on the average price feed (most expensive cities up top).

Key Notes

  • First 10 cities based on parcl_price_feed_aggregate with desc_nulls_last (i.e. remove cities with nulls) test
query MyQuery {
  MSA(where: {MSA_NAME: {_eq: "New York-Newark-Jersey City, NY-NJ-PA"}}) {
    MSA_NAME
    parcl_price_feed_aggregate(limit: 14, order_by: {DATE: desc}) {
      aggregate {
        avg {
          PARCL_PRICE_FEED
        }
      }
    }
    cities(limit: 10, order_by: {parcl_price_feed_aggregate: {avg: {PARCL_PRICE_FEED: desc_nulls_last}}}) {
      CITY_NAME
      parcl_price_feed(limit: 3, order_by: {DATE: desc}) {
        PARCL_PRICE_FEED
        DATE
      }
    }
  }
}

Results

{
  "data": {
    "MSA": [
      {
        "MSA_NAME": "New York-Newark-Jersey City, NY-NJ-PA",
        "parcl_price_feed_aggregate": {
          "aggregate": {
            "avg": {
              "PARCL_PRICE_FEED": 323.92405795264
            }
          }
        },
        "cities": [
          {
            "CITY_NAME": "Sagaponack",
            "parcl_price_feed": [
              {
                "PARCL_PRICE_FEED": 2126.212845698235,
                "DATE": "2022-09-03"
              },
              {
                "PARCL_PRICE_FEED": 2132.548233915626,
                "DATE": "2022-08-10"
              },
              {
                "PARCL_PRICE_FEED": 2132.3287989373653,
                "DATE": "2022-08-01"
              }
            ]
          },
          {
            "CITY_NAME": "Southampton",
            "parcl_price_feed": [
              {
                "PARCL_PRICE_FEED": 1459.0458331086952,
                "DATE": "2022-09-12"
              },
              {
                "PARCL_PRICE_FEED": 1463.6492589239126,
                "DATE": "2022-09-08"
              },
              {
                "PARCL_PRICE_FEED": 1453.1822842065212,
                "DATE": "2022-08-30"
              }
            ]
          },
          {
            "CITY_NAME": "Bridgehampton",
            "parcl_price_feed": [
              {
                "PARCL_PRICE_FEED": 1229.5491853942676,
                "DATE": "2022-10-04"
              },
              {
                "PARCL_PRICE_FEED": 1249.0346063725285,
                "DATE": "2022-09-30"
              },
              {
                "PARCL_PRICE_FEED": 1249.6453128833982,
                "DATE": "2022-09-29"
              }
            ]
          },
          ...
          }
          }

What’s Next