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