CREATE TABLE fruits (
    name text,
    num integer,
    imported date
);


INSERT INTO fruits VALUES ('Grape', 300, '2015-01-08');
INSERT INTO fruits VALUES ('Grape', 260, '2015-02-09');
INSERT INTO fruits VALUES ('Grape', 1353, '2015-03-11');
INSERT INTO fruits VALUES ('Grape', 393, '2015-04-15');
INSERT INTO fruits VALUES ('Grape', 604, '2015-05-12');
INSERT INTO fruits VALUES ('Grape', 542, '2015-06-09');
INSERT INTO fruits VALUES ('Grape', 441, '2015-07-20');
INSERT INTO fruits VALUES ('Grape', 163, '2015-08-27');
INSERT INTO fruits VALUES ('Grape', 297, '2015-09-16');
INSERT INTO fruits VALUES ('Grape', 225, '2015-10-09');
INSERT INTO fruits VALUES ('Grape', 201, '2015-11-10');
INSERT INTO fruits VALUES ('Strawberries', 50, '2015-03-11');
INSERT INTO fruits VALUES ('Strawberries', 32, '2015-04-22');
INSERT INTO fruits VALUES ('Saffron', 536, '2015-05-12');
INSERT INTO fruits VALUES ('Squash', 80, '2015-07-14');
INSERT INTO fruits VALUES ('Citron', 774, '2015-04-02');
INSERT INTO fruits VALUES ('Celery', 12, '2015-04-07');
INSERT INTO fruits VALUES ('Coconut Palm', 26, '2015-09-16');
INSERT INTO fruits VALUES ('Blueberry', 32, '2015-11-16');
INSERT INTO fruits VALUES ('Angelica', 80, '2015-03-20');
INSERT INTO fruits VALUES ('Avocado', 130, '2015-10-19');
INSERT INTO fruits VALUES ('Apple', 140, '2015-07-02');
INSERT INTO fruits VALUES ('Ginger', 255, '2015-06-16');
INSERT INTO fruits VALUES ('Ginger', 160, '2015-06-15');
INSERT INTO fruits VALUES ('Ice Plant', 135, '2015-04-03');
INSERT INTO fruits VALUES ('Ice Plant', 279, '2015-08-04');
INSERT INTO fruits VALUES ('Naranjillo', 126, '2015-07-31');
INSERT INTO fruits VALUES ('Naranjillo', 262, '2015-09-11');

select sum, name, to_char(imported, 'mon') mon, imported from (select sum(num), name, date_trunc('month',imported)::date as imported from fruits group by 2,3) x
\crosstabview +name +mon:imported sum

select sum, name, to_char(imported, 'mon') mon, imported from (select sum(num), 'sum' as name, date_trunc('month',imported)::date as imported from fruits group by 3) x
\crosstabview +name +mon:imported sum

