Skip to content

Comment on Chess in SQLparent

Comments

in sqlite you can do it with FILTER:

   $ sqlite :memory: 
   create table t (product,revenue, year);
   insert into t values ('a',10,2020),('b',14,2020),('c',24,2020),('a',20,2021),('b',24,2021),('c',34,2021);
   select product,sum(revenue) filter (where year=2020) as '2020',sum(revenue) filter (where year=2021) as '2021' from t group by product;
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.