tpch_q18.sql 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  2. --
  3. -- Use of this software is governed by the Business Source License
  4. -- included in the LICENSE file at the root of this repository.
  5. --
  6. -- As of the Change Date specified in that file, in accordance with
  7. -- the Business Source License, use of this software will be governed
  8. -- by the Apache License, Version 2.0.
  9. -- TPC-H Query #Q18, chosen for the workload for its GROUP BY clause
  10. -- We have modified the predicate to sum(l_quantity) > 250
  11. -- to ensure the result updates frequently
  12. -- depends_on: {{ ref('tpch') }}
  13. -- depends_on: {{ ref('tpch_customer') }}
  14. -- depends_on: {{ ref('tpch_orders') }}
  15. -- depends_on: {{ ref('tpch_lineitem') }}
  16. {{ config(materialized='materialized_view', cluster='qa_canary_environment_compute', indexes=[{'default': True}]) }}
  17. SELECT
  18. c_name,
  19. c_custkey,
  20. o_orderkey,
  21. o_orderdate,
  22. o_totalprice,
  23. sum(l_quantity)
  24. FROM
  25. {{ source('tpch','tpch_customer') }} ,
  26. {{ source('tpch','tpch_orders') }} ,
  27. {{ source('tpch','tpch_lineitem') }}
  28. WHERE
  29. o_orderkey IN (
  30. SELECT
  31. l_orderkey
  32. FROM
  33. {{ source('tpch','tpch_lineitem') }}
  34. GROUP BY
  35. l_orderkey having
  36. sum(l_quantity) > 250
  37. )
  38. AND c_custkey = o_custkey
  39. AND o_orderkey = l_orderkey
  40. GROUP BY
  41. c_name,
  42. c_custkey,
  43. o_orderkey,
  44. o_orderdate,
  45. o_totalprice
  46. ORDER BY
  47. o_totalprice DESC,
  48. o_orderdate