tpch_q01.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. -- depends_on: {{ ref('tpch') }}
  11. -- depends_on: {{ ref('tpch_lineitem') }}
  12. {{ config(materialized='materialized_view', cluster='qa_canary_environment_compute', indexes=[{'default': True}]) }}
  13. SELECT
  14. l_returnflag,
  15. l_linestatus,
  16. sum(l_quantity) AS sum_qty,
  17. sum(l_extendedprice) AS sum_base_price,
  18. sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
  19. sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
  20. avg(l_quantity) AS avg_qty,
  21. avg(l_extendedprice) AS avg_price,
  22. avg(l_discount) AS avg_disc,
  23. count(*) AS count_order
  24. FROM
  25. {{ source('tpch', 'tpch_lineitem') }}
  26. WHERE
  27. l_shipdate <= DATE '1998-12-01' - INTERVAL '60' day
  28. GROUP BY
  29. l_returnflag,
  30. l_linestatus
  31. ORDER BY
  32. l_returnflag,
  33. l_linestatus