All problems

Which Industries Buy?

easySQLGroupBy

Loopwire's marketing lead is deciding which sector to aim next quarter's campaigns at, and wants to start from what the customer base is actually made of today. Each customer company is tagged with the industry it works in. The suspicion in the room is that Loopwire keeps selling to the same kind of business without noticing, and a plain tally either confirms that or kills the theory.

accounts — one row per customer company. industry is the sector that company works in; signup_date is the day it created its Loopwire account.

id company_name industry signup_date
1 Northwind Traders retail 2022-11-03
2 Vertex Analytics software 2022-12-15
3 Bluepeak Logistics logistics 2023-01-20
4 Fernwood Studio media 2023-02-05
5 Cobalt Health healthcare 2023-02-18
6 Ridgeline Capital finance 2023-03-01
7 Sable & Co retail 2023-03-22
8 Hearth Robotics manufacturing 2023-04-10

The table already exists in the database — there is nothing to create or load.

Task: Write a query that returns one row per industry, with columns industry and n, n being how many companies carry that industry tag. Largest group first; industries on the same count are listed alphabetically by industry name.

Example output

Shape only — these sectors and figures are invented:

industry n
energy 4
education 2
hospitality 2
insurance 1
nonprofit 1

(...2 more rows not shown)

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…