Explore this snippet with some demo data here.
Bar charts are perhaps the most common charts used in data analysis. They have one categorical or temporal axis, and one numerical axis.
You just need a simple GROUP BY to get all the elements you need for a bar chart:
SELECT AGG_FN(<COLUMN>) as metric, <CATEGORICAL_COLUMN> as cat FROM <TABLE> GROUP BY cat
AGG_FNis an aggregation function like
COLUMNis the column you want to aggregate to get your metric. Make sure this is a numeric column.
CATEGORICAL_COLUMNis the group you want to show on the x-axis. Make sure this is a date, datetime, timestamp, or time column (not a number)
In this example with some Spotify data, we’ll look at the average daily streams by month of year:
select avg(streams) avg_daily_streams, MONTH(day) month from ( select sum(streams) streams, day from PUBLIC.SPOTIFY_DAILY_TRACKS group by day ) group by month