Inputs
An existing SQLite data base.
Outputs
The results of a SQL query are output to the history as a tabular file.
For help in using SQLite see: http://www.sqlite.org/docs.html
NOTE: input for SQLite dates input field must be in the format: YYYY-MM-DD for example: 2015-09-30
See: http://www.sqlite.org/lang_datefunc.html
Example
Given 2 tabular datasets: customers and sales
Dataset customers
Table name: "customers"
Column names: "CustomerID,FirstName,LastName,Email,DOB,Phone"
#CustomerID FirstName LastName DOB Phone 1 John Smith John.Smith@yahoo.com 1968-02-04 626 222-2222 2 Steven Goldfish goldfish@fishhere.net 1974-04-04 323 455-4545 3 Paula Brown pb@herowndomain.org 1978-05-24 416 323-3232 4 James Smith jim@supergig.co.uk 1980-10-20 416 323-8888 Dataset sales
Table name: "sales"
Column names: "CustomerID,Date,SaleAmount"
#CustomerID Date SaleAmount 2 2004-05-06 100.22 1 2004-05-07 99.95 3 2004-05-07 122.95 3 2004-05-13 100.00 4 2004-05-22 555.55 The query
SELECT FirstName,LastName,sum(SaleAmount) as "TotalSales" FROM customers join sales on customers.CustomerID = sales.CustomerID GROUP BY customers.CustomerID ORDER BY TotalSales DESC;Produces this tabular output:
#FirstName LastName TotalSales James Smith 555.55 Paula Brown 222.95 Steven Goldfish 100.22 John Smith 99.95 If the optional Table name and Column names inputs are not used, the query would be:
SELECT t1.c2 as "FirstName", t1.c3 as "LastName", sum(t2.c3) as "TotalSales" FROM t1 join t2 on t1.c1 = t2.c1 GROUP BY t1.c1 ORDER BY TotalSales DESC;You can selectively name columns, e.g. on the customers input you could just name columns 2,3, and 5:
Column names: ,FirstName,LastName,,BirthDate
Results in the following data base table
#c1 FirstName LastName c4 BirthDate c6 1 John Smith John.Smith@yahoo.com 1968-02-04 626 222-2222 2 Steven Goldfish goldfish@fishhere.net 1974-04-04 323 455-4545 3 Paula Brown pb@herowndomain.org 1978-05-24 416 323-3232 4 James Smith jim@supergig.co.uk 1980-10-20 416 323-8888 Regular_expression functions are included for:
matching: re_match('pattern',column) SELECT t1.FirstName, t1.LastName FROM t1 WHERE re_match('^.*\.(net|org)$',c4)Results:
#FirstName LastName Steven Goldfish Paula Brown searching: re_search('pattern',column) substituting: re_sub('pattern','replacement,column) SELECT t1.FirstName, t1.LastName, re_sub('^\d{2}(\d{2})-(\d\d)-(\d\d)','\3/\2/\1',BirthDate) as "DOB" FROM t1 WHERE re_search('[hp]er',c4)Results:
#FirstName LastName DOB Steven Goldfish 04/04/74 Paula Brown 24/05/78 James Smith 20/10/80