Bar

Example Bar Charts

Basic Bar Chart

-- @chart: bar
-- @title: Bar Chart
-- @subtitle: An basic example of a bar chart
SELECT 
Channel,
count(*) as Won_Sales
FROM Sales
WHERE Status = 'Won'
GROUP BY Channel
ORDER BY Won_Sales DESC;
CHANNELWON_SALES

pr_ad

21.0

coldcall

37.0

search

66.0

event

112.0

referral

243.0

Bar chart with Parent and Sub Category Groups

-- @chart: bar
-- @title: Groups - Multiple category groups
-- @subtitle: An example of multiple category groups
-- @groups: Channel, Owner
-- @series: TotalSales
-- @formats: currency
SELECT 
	Final.*
FROM (  
  SELECT 
  	Channel,    
  	Owner,
    (
      SELECT sum(Sub.Amount)
      FROM Sales Sub
      WHERE Sub.Channel = Sales.Channel
    ) as TotalChannelSales,
    sum(Amount) as TotalSales
  FROM Sales
  WHERE Owner IN (
    SELECT Owner
    FROM Sales
    GROUP BY Owner
    ORDER BY sum(Amount)
    LIMIT 10
  )
  GROUP BY Channel, Owner
) as Final
ORDER BY TotalChannelSales DESC, TotalSales DESC
CHANNELOWNERTOTALCHANNELSALESTOTALSALES

pr_ad

Kim

9181300.0

84603.0

pr_ad

Roger

9181300.0

118985.0

pr_ad

Lucy

9181300.0

138374.0

pr_ad

Norbit

9181300.0

141711.0

pr_ad

Justice

9181300.0

160517.0

pr_ad

Heather

9181300.0

239870.0

pr_ad

Peter

9181300.0

266655.0

pr_ad

Tammy

9181300.0

501805.0

coldcall

Justice

1.7372264E7

87207.0

coldcall

Heather

1.7372264E7

162974.0

coldcall

Norbit

1.7372264E7

333648.0

Bar Chart with Formats

-- @chart: bar
-- @title: Bar Chart With Formats
-- @subtitle: An example bar chart with formats
-- @formats: currency
SELECT 
Channel,
sum(Amount) as Total_Sales
FROM Sales
WHERE Status = 'Won'
GROUP BY Channel
ORDER BY Total_Sales DESC;
CHANNELTOTAL_SALES

pr_ad

1716590.0

coldcall

3267837.0

search

6320993.0

event

1.1198055E7

referral

2.6029056E7

Bar with Stacking

-- @chart: bar
-- @title: Bar Stacking - Example bar chart with stacking
-- @groups: Owner, Channel
-- @subtitle: An example bar chart that has a single stack
-- @formats: currency
-- @series: Sales
-- @stacks: Channel
SELECT *
FROM (  
  SELECT 
      Owner,
      Channel,
      (
        SELECT sum(Amount)
        FROM Sales Sub
        WHERE Sub.Owner = Sales.Owner
      ) as OwnerTotal,
      sum(amount) as Sales
  FROM sales
  GROUP BY Owner, Channel
) as Final
ORDER BY Final.OwnerTotal ASC, Sales DESC;
OWNERCHANNELOWNERTOTALSALES

Roger

referral

1459150.0

607758.0

Roger

coldcall

1459150.0

365129.0

Roger

search

1459150.0

223080.0

Roger

event

1459150.0

144198.0

Roger

pr_ad

1459150.0

118985.0

Lucy

referral

1460022.0

914463.0

Lucy

event

1460022.0

267908.0

Lucy

search

1460022.0

139277.0

Lucy

pr_ad

1460022.0

138374.0

Kim

referral

1768826.0

1338296.0

Kim

search

1768826.0

177605.0

Kim

event

1768826.0

168322.0

Kim

pr_ad

1768826.0

84603.0

Grenda

referral

2411989.0

1567753.0

Grenda

event

2411989.0

511020.0

Grenda

search

2411989.0

333216.0

Irene

referral

2798575.0

1698665.0

Irene

search

2798575.0

706034.0

Irene

event

2798575.0

393876.0

Norbit

referral

2921665.0

1282432.0

Norbit

event

2921665.0

722410.0

Norbit

search

2921665.0

441464.0

Norbit

coldcall

2921665.0

333648.0

Norbit

pr_ad

2921665.0

141711.0

Justice

referral

3292632.0

1971882.0

Justice

search

3292632.0

638796.0

Justice

event

3292632.0

434230.0

Justice

pr_ad

3292632.0

160517.0

Heading

Last updated

Support

DiscordX

ChartSQL