BEGIN TRANSACTION;
CREATE TABLE `animal` (
`id` INTEGER UNIQUE,
`type` TEXT,
`name` TEXT,
PRIMARY KEY(id)
);
INSERT INTO `animal` VALUES
(1,'cat','Felix'),
(2,'cat','Sylvester'),
(3,'cat','Garfield'),
(4,'lion','Simba'),
(5,'lion','Elsa'),
(6,'tiger','Sher Khan'),
(7,'tiger','Woods'),
(8,'dog','Rover');
CREATE INDEX `by-type` ON `animal` (`type` ASC);
COMMIT;
CREATE VIEW Summary AS
Select type, count(*)
FROM animal
GROUP by type;
CREATE VIEW cats_only AS
SELECT id,name
FROM animal
WHERE type='cat';
####
$sqlite3 animal.sqlite '.read animal.sql'
####
$ sqlite3 -header -column animal.sqlite
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
sqlite> select * from summary;
type count(*)
---------- ----------
cat 3
dog 1
lion 2
tiger 2
sqlite> select * from cats_only;
id name
---------- ----------
1 Felix
2 Sylvester
3 Garfield
sqlite> .q