Skip to content

Instantly share code, notes, and snippets.

@bsullins
Created October 12, 2016 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsullins/e2bc321d5f50400a00f2c9f4162055b5 to your computer and use it in GitHub Desktop.
Save bsullins/e2bc321d5f50400a00f2c9f4162055b5 to your computer and use it in GitHub Desktop.
I receive the error when trying to add a column to the list of the last select just before the count() aggregate
-- checkout client data
select *
from clients;
-- how many rows do we have?
-- 35,749
select count(1)
from sales_all_years
-- inner join from sales
-- 35,749
select count(1)
from sales_all_years s
join clients c on s.companyname = c.name
-- Add details about clients for a more comprehensive answer
select
c.marketcaplabel,
c.marketcapamount,
c.name,
c.ipoyear,
c.symbol,
count(distinct s.orderid) OrderCount,
sum(s.saleamount) as TotalSales
from sales_all_years s
join clients c on s.companyname = c.name
group by
c.marketcaplabel,
c.marketcapamount,
c.name,
c.ipoyear,
c.symbol
order by
c.marketcapamount desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment