Try this.

BEGIN TRANSACTION;
CREATE TABLE sales(SaleDate date,SaleVolume int);
INSERT INTO "sales" VALUES('2010-01-01', 10);
INSERT INTO "sales" VALUES('2010-01-02', 20);
INSERT INTO "sales" VALUES('2011-01-01', 15);
INSERT INTO "sales" VALUES('2011-01-02', 30);
INSERT INTO "sales" VALUES('2009-01-01', 5);
INSERT INTO "sales" VALUES('2009-01-02', 10);
COMMIT;

select strftime('%Y',SaleDate) as year,total(SaleVolume),coalesce((select 
total(SaleVolume) from sales),'dummy') from sales where SaleDate >= 
date('now','start of year','-1 year') group by year;

2010|30.0|90.0
2011|45.0|90.0


Michael D. Black
Senior Scientist
NG Information Systems
Advanced Analytics Directorate



________________________________________
From: [email protected] [[email protected]] on 
behalf of Kai Peters [[email protected]]
Sent: Sunday, March 20, 2011 11:10 PM
To: General Discussion of SQLite Database
Subject: EXT :[sqlite] Newbie question

Hi all,

given a table with two columns (SaleDate, SaleVolume) is it possible in one 
query to obtain
the following three column result set:

SalesCurrentYear, SalesLastYEar, SalesAllyears

?

Thanks as always for any help,
Kai


_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to