logo

Back to questions

App Click-through Rate (CTR)

Easy

This is the same question as problem #1 in the SQL Chapter of Ace the Data Science Interview!

Assume you have an events table on app analytics. Write a query to get the click-through rate (CTR %) per app in 2022. Output the results in percentages rounded to 2 decimal places.

Notes:

  • To avoid integer division, you should multiply the click-through rate by 100.0, not 100.
  • Percentage of click-through rate = 100.0 * Number of clicks / Number of impressions

Table:

Column NameType
app_idinteger
event_typestring
timestampdatetime

Example Input:

app_idevent_typetimestamp
123impression07/18/2022 11:36:12
123impression07/18/2022 11:37:12
123click07/18/2022 11:37:42
234impression07/18/2022 14:15:12
234click07/18/2022 14:16:12

Example Output:

app_idctr
12350.00
234100.00

Explanation

App 123 has a CTR of 50.00% because this app receives 1 click out of the 2 impressions. Hence, it's 1/2 = 50.00%.

PostgreSQL 14

Refer friends to get bonus content & cool prizes.