BaşlayınÜcretsiz Başlayın

CTE’lerle optimize etme

CTE’ler, ana sorguda verilerle çalışmadan önce toplama gibi hesaplamaları ele alarak sorguları optimize etmene de yardımcı olur.

Örneğin, sipariş öğe sayısına göre en yüksek ödeme sayısını bulmak istiyorsun. Bu egzersiz, bunu bir CTE ile nasıl verimli şekilde yapacağını gösterecek.

Bu egzersiz

BigQuery'ye Giriş

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Alt sorguda ve ana sorguda doğru toplu (aggregate) fonksiyonları ekle.
  • Ana sorguda order_items sütununu iki kez kullanarak, her siparişteki öğe sayısını bulmak için ARRAY_LENGTH kullan.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

WITH payments AS (
  SELECT
    -- Use the correct aggregate to find the highest number of payments
    ___(payment_sequential) AS num_payments,
    order_id
  FROM ecommerce.ecomm_payments 
  -- Group the results by order
  GROUP BY ___)
     
SELECT
  -- Add the correct function to find the length or number of order items
  ___(o.order_items) AS num_items,
  MAX(p.num_payments) AS max_payments
FROM ecommerce.ecomm_orders o
JOIN payments p
-- Add the correct keyword to join using the same column
___ (order_id)
-- Add the correct function to find the length or number of order items
GROUP BY ___(o.order_items)
Kodu Düzenle ve Çalıştır