Count articles per tag
A CMS keeps an array of tags right on the article row — e.g. {'sql', 'postgres', 'index'}. Analytics wants a «top tags» view: how many articles are tagged with each tag. To compute this, the array must be «unfolded» into rows — every array element becomes a separate row, then it's a regular grouping.
The table articles(id, title, tags TEXT[]) holds three articles. For every tag present in the arrays, count the number of articles that contain it. Sort by count descending, ties broken by tag alphabetically.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| n | tag |
|---|---|
| 3 | sql |
| 2 | postgres |
| 1 | index |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in