TiDB Cloud Logo
TiDB LogoBack to labs
Top
Time range
-- It is a particularly resource-intensive analytical query.
-- There is an event table with 109,950,743 rows of the same data in both MySQL and TiDB instances. 
WITH top_sellers AS (
      SELECT 
            product_id, 
            SUM(price) AS sold
      FROM events
      WHERE event_type = 'purchase'
            AND event_time >= '${start_time}'
            AND event_time <= '${end_time}'
      GROUP BY product_id
      ORDER BY sold DESC
      LIMIT ${top_n}
)
SELECT 
      products.product_id, 
      products.product_name, 
      top_sellers.sold
FROM top_sellers
JOIN products ON top_sellers.product_id = products.product_id
ORDER BY sold DESC
MySQL RDS
your results will display here
TiDB Logo
TiDB Cloud Serverless
your results will display here

Copyright © PingCAP 2025.