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_merchandises AS (
      SELECT 
          product_id, 
          COUNT(*) AS viewed
      FROM events
      WHERE event_type = 'view'
          AND event_time >= '${start_time}'
          AND event_time <= '${end_time}'
      GROUP BY product_id
      ORDER BY viewed DESC
      LIMIT ${top_n}
)
SELECT 
      products.product_id, 
      products.product_name, 
      top_merchandises.viewed
FROM top_merchandises
JOIN products ON top_merchandises.product_id = products.product_id
ORDER BY viewed DESC
MySQL RDS
your results will display here
TiDB Logo
TiDB Cloud Serverless
your results will display here

Copyright © PingCAP 2025.