Library › Coding AI › Marketing and content

Count customers by their first-touch channel in SQL

Practice: Giving the right context. About 5 minutes.

About this exercise

Write one SQL query that counts Q3 2026 customers (first_order_at from July 1 up to October 1) by the channel of their first touch, meaning the earliest touch at or before their first order. Break ties on the same timestamp with the lower touch id. Return two columns named exactly first_channel and customer_count, biggest first. One code block, at most 20 lines, then under 25 words outside the code.

Common mistakes when you ask AI for this

  • Leaving the attribution rule open. The AI may use last touch, or count touches after the order. Try: Add: "First touch = earliest touch at or before the first order."
  • Forgetting ties. Two touches at the same second make the pick random. Try: Add: "Break ties with the lower touch id."
  • Leaving the cohort vague. The AI counts every customer ever, or uses order dates loosely. Try: Add: "Customers with first_order_at in Q3 2026."
  • Leaving the output open. The AI picks its own column names, so the dashboard that reads this breaks. Try: Add: "Columns first_channel and customer_count, biggest first."
  • Getting a menu of options. The AI likes to offer two or three versions of the query, so you're left to pick and test them yourself. Try: Add: "Give one query only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."

What a strong prompt includes

  • Defines first touch
  • Breaks ties
  • Sets the quarter
  • Sets the output
  • Asks for one answer only

Practice this now ↑

Related exercises