CTEs के साथ डेटा फ़िल्टर करना
CTE का एक प्रभावी उपयोग यह है कि आप क्वेरी के आगे इस्तेमाल करने से पहले CTE में ही डेटा फ़िल्टर कर लें. इससे अंतिम क्वेरी में कम डेटा आता है और कुल लागत घटती है. यह क्वेरी उन ऑर्डर्स का order status ढूँढने में मदद करेगी जिनके आइटम्स की कीमत $150 से अधिक है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
BigQuery परिचय
अभ्यास निर्देश
- एक नया CTE
ordersबनाएँ जो $150 से अधिक कीमत वाले ऑर्डर्स चुने, इसके लिएorder_itemsको UNNEST करकेpriceकॉलम पाएँ. - CTE के परिणामों को
ecomm_order_detailsडेटासेट से JOIN करें ताकिorder_statusकी संख्या मिले और हर status में ऑर्डर्स कोCOUNTकरके एग्रीगेट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
-- 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