शुरू करेंमुफ़्त में शुरू करें

RANK और LEAD/LAG

Rankings आपको किसी भी विशेष क्रम में अपने डेटा को रैंक करने देती हैं, जबकि LAG और LEAD फंक्शन आपको अपनी क्वेरी की विंडो में पीछे या आगे देखने देते हैं। ये टूल्स असरदार रिपोर्ट बनाने और LAG/LEAD के मामले में और भी जटिल विश्लेषणात्मक फंक्शन तैयार करने में मदद करते हैं। यहाँ, आप इन्हें हमारे डेटा के साथ अभ्यास में लागू करेंगे।

यह अभ्यास पाठ्यक्रम का हिस्सा है

BigQuery परिचय

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

-- Complete the query to order customers by the total amount spent

-- First, write a CTE to group customers and find their total amount spent
WITH orders AS (
  SELECT
  -- Add the correct columns and aggregate functions
  ___,
  SUM(___) as all_items
  FROM ecommerce.ecomm_orders o, UNNEST(o.order_items) items
  JOIN ecommerce.ecomm_order_details od USING (order_id)
  GROUP BY od.customer_id
)

SELECT
	customer_id,
	all_items,
-- Fill in the RANK window function and OVER clause
RANK() ___(ORDER BY ___ DESC)
FROM orders
ORDER BY all_items DESC;
कोड संपादित करें और चलाएँ