Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 1.11 KB

horizontal-bar.md

File metadata and controls

35 lines (28 loc) · 1.11 KB

Horizontal bar chart

Explore this snippet with some demo data here.

Description

Horizontal Bar charts are ideal for comparing a particular metric across a group of values. They have bars along the x-axis and group names along the y-axis. You just need a simple GROUP BY to get all the elements you need for a horizontal bar chart:

SELECT 
   AGG_FN(<COLUMN>) as metric,
   <GROUP_COLUMN> as group
FROM 
   <TABLE>
GROUP BY
   group

where:

  • AGG_FN is an aggregation function like SUM, AVG, COUNT, MAX, etc.
  • COLUMN is the column you want to aggregate to get your metric. Make sure this is a numeric column.
  • GROUP_COLUMN is the group you want to show on the y-axis. Make sure this is a categorical column (not a number)

Usage

In this example with some Spotify data, we'll compare the total streams by artist:

select
  sum(streams) streams, 
  artist 
from PUBLIC.SPOTIFY_DAILY_STREAMS
group by artist

horizontal-bar