End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
ad_id: Aggregate the data by ad_id to calculate metrics for each ad.SUM(action = 'Clicked') and SUM(action = 'Viewed').IFNULL to replace NULL with 0.ROUND function to round the CTR to two decimal places.ad_id in ascending order in case of a tie.ad_id and the calculated ctr for the final output.
erDiagram
Ads {
int ad_id
int user_id
enum action
ad_id user_id PK
}