sqlbeginner
String Aggregation with GROUP BY
Concatenate grouped values into comma-separated strings using STRING_AGG with ordering and filtering.
sqlPress ⌘/Ctrl + Shift + C to copy
-- Aggregate tags per post
SELECT
p.id,
p.title,
STRING_AGG(t.name, ', ' ORDER BY t.name) AS tags
FROM posts p
JOIN post_tags pt ON pt.post_id = p.id
JOIN tags t ON t.id = pt.tag_id
GROUP BY p.id, p.title;
-- With DISTINCT to remove duplicates
SELECT
department,
STRING_AGG(DISTINCT skill, ', ' ORDER BY skill) AS skills
FROM employees
GROUP BY department
HAVING COUNT(*) > 3;Use Cases
- Tag lists per item
- Comma-separated emails
- Report summaries
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
sqlbeginner
Aggregate Strings with STRING_AGG / GROUP_CONCAT
Concatenate values from multiple rows into a single string per group.
Best for: Comma-separated lists in reports
#sql#string-agg
pythonintermediate
Pandas GroupBy Aggregation Examples
GroupBy operations with multiple aggregations, named aggregations, and transform for DataFrame analysis.
Best for: Sales reporting by region and time period
#pandas#groupby
pythonintermediate
Pandas Custom Aggregation Functions
Pass custom lambda and named functions to .agg() for complex groupby aggregations.
Best for: HR analytics
#pandas#groupby
pythonbeginner
Pandas Pivot Table Summary
Create multi-level summary pivot tables from transactional data using pd.pivot_table.
Best for: sales reporting
#pandas#pivot-table