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ırEgzersiz talimatları
pricesütununu bulmak içinorder_items'i unnest ederek, 150 $ üzeri fiyata sahip siparişler içinordersadlı yeni bir CTE oluştur.- CTE'nin sonuçlarını
ecomm_order_detailsveri kümesiyle birleştir veorder_statussayılarını bulmak için her durumdaki siparişleriCOUNTile 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