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

CTE'lerle veriyi filtreleme

CTE kullanmanın en etkili yollarından biri, sorgunun ilerleyen kısmında kullanmadan önce veriyi CTE içinde filtrelemektir. Bu, son sorguya daha az veri taşıyarak toplam sorgu maliyetini düşürür. Bu sorgu, 150 $ üzeri fiyata sahip ürünleri içeren siparişlerin sipariş durumunu bulmamıza yardımcı olacak.

Bu egzersiz

BigQuery'ye Giriş

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

Egzersiz talimatları

  • price sütununu bulmak için order_items'i unnest ederek, 150 $ üzeri fiyata sahip siparişler için orders adlı yeni bir CTE oluştur.
  • CTE'nin sonuçlarını ecomm_order_details veri kümesiyle birleştir ve order_status sayılarını bulmak için her durumdaki siparişleri COUNT ile toplayarak grupla.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

-- Add the correct items to finish our filtered CTE

-- Create a new CTE with the name orders
WITH ___ AS (
  SELECT order_id
  -- Add the correct column for the order item details
  FROM ecommerce.ecomm_orders, UNNEST(___) items
  -- Fill in the correct column for the item price 
  WHERE items.___ > 150
)

SELECT
	-- Aggregate to find the total number of orders
	___(order_id),
	-- Add the column for the status of the order
	___
FROM ecommerce.ecomm_order_details od
JOIN orders o USING (order_id)
GROUP BY order_status
Kodu Düzenle ve Çalıştır