Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

688 B
Raw Blame
SELECT 
  cntrycode,
  count(*) AS numcust,
  sum(acctbal) AS totacctbal
FROM
  (
    SELECT
      substr(c.phone,1,2) AS cntrycode,
      c.acctbal
    FROM
      customer c
    WHERE
      substr(c.phone,1,2) IN ('13', '31', '23', '29', '30', '18', '17')
      AND c.acctbal > (
        SELECT
          avg(c.acctbal)
        FROM
          customer c
        WHERE
          c.acctbal > 0.00
          AND substr(c.phone,1,2) IN ('13', '31', '23', '29', '30', '18', '17')
      )
      AND NOT EXISTS (
        SELECT
          *
        FROM
          orders o
        WHERE
          o.custkey = c.custkey
      )
  ) AS custsale
GROUP BY
  cntrycode
ORDER BY
  cntrycode
LIMIT 20
;