You are on page 1of 8

sqlite> .

tables
sqlite> .open Library.db
sqlite> .databases
main: D:\Prof_C\sqLite\Library.db
sqlite> .tables
AUTORS BOOKS DGRANNBOOKS LinkTable PUBLISHERS
sqlite> .mode columns
sqlite> .header on
sqlite> .schema BOOKS
CREATE TABLE IF NOT EXISTS "BOOKS"(
BK_ID INT,
BK_NAME TEXT,
PB_ID INT,
BK_PAGES INT
, BK_PRICE REAL);
sqlite> SELECT * FROM PUBLISHERS;
PB_ID PB_NAME
---------- ----------
1 Vintage
2 Vintage Bo
3 Addison-We
4 Celadon Bo
5 Atlantic M
6 Sarah Cric
7 Delacorte
sqlite> .width 8 30
sqlite> SELECT * FROM PUBLISHERS;
PB_ID PB_NAME
-------- ------------------------------
1 Vintage
2 Vintage Books
3 Addison-Wesley Professional
4 Celadon Books
5 Atlantic Monthly Press
6 Sarah Crichton Books
7 Delacorte Books for Young Read
sqlite> .width 8 35
sqlite> SELECT * FROM PUBLISHERS;
PB_ID PB_NAME
-------- -----------------------------------
1 Vintage
2 Vintage Books
3 Addison-Wesley Professional
4 Celadon Books
5 Atlantic Monthly Press
6 Sarah Crichton Books
7 Delacorte Books for Young Readers
sqlite> SELECT * FROM BOOKS;
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
-------- ----------------------------------- ---------- ---------- ----------
1 Killers of the Flower Moon:The Osag 1 400 12.17
2 The Lost City of Z: A Tale of Deadl 2 400 10.0
3 The C++ Standard Library: A Tutoria 3 1136 64.58
4 C++ Templates: The Complete Guide ( 3 832 63.98
5 The Silent Patient 4 336 16.19
6 A Long Way Gone: Memoirs of a Boy S 6 229 5.59
7 Are You There God? It's Me, Margare 7 160 6.96
sqlite> SELECT BK_NAME, BK_PRICE, BK_ID FROM BOOKS;
BK_NAME BK_PRICE BK_ID
-------- ----------------------------------- ----------
Killers 12.17 1
The Lost 10.0 2
The C++ 64.58 3
C++ Temp 63.98 4
The Sile 16.19 5
A Long W 5.59 6
Are You 6.96 7
sqlite> SELECT BK_ID, BK_NAME, BK_PRICE FROM BOOKS;
BK_ID BK_NAME BK_PRICE
-------- ----------------------------------- ----------
1 Killers of the Flower Moon:The Osag 12.17
2 The Lost City of Z: A Tale of Deadl 10.0
3 The C++ Standard Library: A Tutoria 64.58
4 C++ Templates: The Complete Guide ( 63.98
5 The Silent Patient 16.19
6 A Long Way Gone: Memoirs of a Boy S 5.59
7 Are You There God? It's Me, Margare 6.96
sqlite> .width 6 40
sqlite> SELECT BK_ID, BK_NAME, BK_PRICE FROM BOOKS;
BK_ID BK_NAME BK_PRICE
------ ---------------------------------------- ----------
1 Killers of the Flower Moon:The Osage Mur 12.17
2 The Lost City of Z: A Tale of Deadly Obs 10.0
3 The C++ Standard Library: A Tutorial and 64.58
4 C++ Templates: The Complete Guide (2nd E 63.98
5 The Silent Patient 16.19
6 A Long Way Gone: Memoirs of a Boy Soldie 5.59
7 Are You There God? It's Me, Margaret 6.96
sqlite> SELECT * FROM BOOKS WHERE BK_PRICE > 50
...>
...> SELECT * FROM BOOKS WHERE BK_PRICE > 5
...> SELECT * FROM BOOKS WHERE BK_PRICE > 50;
Error: near "SELECT": syntax error
sqlite> SELECT * FROM BOOKS WHERE BK_PAGES > 500;
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
4 C++ Templates: The Complete Guide (2nd E 3 832 63.98
sqlite> SELECT * FROM BOOKS WHERE BK_PRICE > 50;
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
4 C++ Templates: The Complete Guide (2nd E 3 832 63.98
sqlite> SELECT * FROM BOOKS WHERE BK_PRICE < 50;
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
1 Killers of the Flower Moon:The Osage Mur 1 400 12.17
2 The Lost City of Z: A Tale of Deadly Obs 2 400 10.0
5 The Silent Patient 4 336 16.19
6 A Long Way Gone: Memoirs of a Boy Soldie 6 229 5.59
7 Are You There God? It's Me, Margaret 7 160 6.96
sqlite> SELECT * FROM BOOKS WHERE BK_PRICE > 10.5 AND BK_PRICE < 50;
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
1 Killers of the Flower Moon:The Osage Mur 1 400 12.17
5 The Silent Patient 4 336 16.19
sqlite> SELECT * FROM BOOKS WHERE BK_NAME LIKE "the%";
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
2 The Lost City of Z: A Tale of Deadly Obs 2 400 10.0
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
5 The Silent Patient 4 336 16.19
sqlite> SELECT * FROM BOOKS WHERE BK_NAME LIKE "%C++%";
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
4 C++ Templates: The Complete Guide (2nd E 3 832 63.98
sqlite> SELECT * FROM BOOKS WHERE BK_NAME LIKE "%the%";
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
1 Killers of the Flower Moon:The Osage Mur 1 400 12.17
2 The Lost City of Z: A Tale of Deadly Obs 2 400 10.0
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
4 C++ Templates: The Complete Guide (2nd E 3 832 63.98
5 The Silent Patient 4 336 16.19
7 Are You There God? It's Me, Margaret 7 160 6.96
sqlite> SELECT * FROM BOOKS WHERE BK_NAME LIKE "%the_";
sqlite> SELECT * FROM BOOKS WHERE BK_NAME LIKE "%the %";
BK_ID BK_NAME PB_ID BK_PAGES BK_PRICE
------ ---------------------------------------- ---------- ----------
----------
1 Killers of the Flower Moon:The Osage Mur 1 400 12.17
2 The Lost City of Z: A Tale of Deadly Obs 2 400 10.0
3 The C++ Standard Library: A Tutorial and 3 1136 64.58
4 C++ Templates: The Complete Guide (2nd E 3 832 63.98
5 The Silent Patient 4 336 16.19
sqlite> SELECT BOOKS.BK_NAME, PB_NAME FROM JOIN PUBLISHERS ON BOOKS.PB_ID =
PUBLISHERS.PB_ID;
Error: near "JOIN": syntax error
sqlite> SELECT BOOKS.BK_NAME, PB_NAME FROM BOOKS JOIN PUBLISHERS ON BOOKS.PB_ID =
PUBLISHERS.PB_ID;
BK_NAM PB_NAME
------ ----------------------------------------
Killer Vintage
The Lo Vintage Books
The C+ Addison-Wesley Professional
C++ Te Addison-Wesley Professional
The Si Celadon Books
A Long Sarah Crichton Books
Are Yo Delacorte Books for Young Readers
sqlite> .width 50 40
sqlite> SELECT BOOKS.BK_NAME, PB_NAME FROM BOOKS JOIN PUBLISHERS ON BOOKS.PB_ID =
PUBLISHERS.PB_ID;
BK_NAME PB_NAME
--------------------------------------------------
----------------------------------------
Killers of the Flower Moon:The Osage Murders and t Vintage
The Lost City of Z: A Tale of Deadly Obsession in Vintage Books
The C++ Standard Library: A Tutorial and Reference Addison-Wesley Professional
C++ Templates: The Complete Guide (2nd Edition) Addison-Wesley Professional
The Silent Patient Celadon Books
A Long Way Gone: Memoirs of a Boy Soldier Sarah Crichton Books
Are You There God? It's Me, Margaret Delacorte Books for Young
Readers
sqlite> SELECT PB_NAME, BOOKS.BK_NAME FROM BOOKS JOIN PUBLISHERS ON BOOKS.PB_ID =
PUBLISHERS.PB_ID;
PB_NAME BK_NAME
--------------------------------------------------
----------------------------------------
Vintage Killers of the Flower Moon:The
Osage Mur
Vintage Books The Lost City of Z: A Tale of
Deadly Obs
Addison-Wesley Professional The C++ Standard Library: A
Tutorial and
Addison-Wesley Professional C++ Templates: The Complete
Guide (2nd E
Celadon Books The Silent Patient
Sarah Crichton Books A Long Way Gone: Memoirs of a
Boy Soldie
Delacorte Books for Young Readers Are You There God? It's Me,
Margaret
sqlite> SELECT PB_NAME, BOOKS.BK_NAME FROM BOOKS JOIN PUBLISHERS ON
PUBLISHERS.PB_ID = BOOKS.PB_ID;
PB_NAME BK_NAME
--------------------------------------------------
----------------------------------------
Vintage Killers of the Flower Moon:The
Osage Mur
Vintage Books The Lost City of Z: A Tale of
Deadly Obs
Addison-Wesley Professional The C++ Standard Library: A
Tutorial and
Addison-Wesley Professional C++ Templates: The Complete
Guide (2nd E
Celadon Books The Silent Patient
Sarah Crichton Books A Long Way Gone: Memoirs of a
Boy Soldie
Delacorte Books for Young Readers Are You There God? It's Me,
Margaret
sqlite> SELECT PB_NAME, BK_NAME from PUBLISHERS left join BOOKS on BOOKS.PB_ID =
PUBLISHERS.PB_ID;
PB_NAME BK_NAME
--------------------------------------------------
----------------------------------------
Vintage Killers of the Flower Moon:The
Osage Mur
Vintage Books The Lost City of Z: A Tale of
Deadly Obs
Addison-Wesley Professional C++ Templates: The Complete
Guide (2nd E
Addison-Wesley Professional The C++ Standard Library: A
Tutorial and
Celadon Books The Silent Patient
Atlantic Monthly Press
Sarah Crichton Books A Long Way Gone: Memoirs of a
Boy Soldie
Delacorte Books for Young Readers Are You There God? It's Me,
Margaret
sqlite> SELECT PB_NAME, BK_NAME from PUBLISHERS left join BOOKS on BOOKS.PB_ID =
PUBLISHERS.PB_ID ORDER BY BK_NAME ASC;
PB_NAME BK_NAME
--------------------------------------------------
----------------------------------------
Atlantic Monthly Press
Sarah Crichton Books A Long Way Gone: Memoirs of a
Boy Soldie
Delacorte Books for Young Readers Are You There God? It's Me,
Margaret
Addison-Wesley Professional C++ Templates: The Complete
Guide (2nd E
Vintage Killers of the Flower Moon:The
Osage Mur
Addison-Wesley Professional The C++ Standard Library: A
Tutorial and
Vintage Books The Lost City of Z: A Tale of
Deadly Obs
Celadon Books The Silent Patient
sqlite> SELECT PB_NAME, COUNT(BK_NAME) FROM PUBLISHERS LEFT JOIN BOOKS ON
BOOKS.PB_ID = PUBLISHERS.PB_ID;
PB_NAME COUNT(BK_NAME)
--------------------------------------------------
----------------------------------------
Vintage 7
sqlite> SELECT PB_NAME, COUNT(BK_NAME) FROM PUBLISHERS LEFT JOIN BOOKS ON
BOOKS.PB_ID = PUBLISHERS.PB_ID GROUP BY PB_NAME;
PB_NAME COUNT(BK_NAME)
--------------------------------------------------
----------------------------------------
Addison-Wesley Professional 2
Atlantic Monthly Press 0
Celadon Books 1
Delacorte Books for Young Readers 1
Sarah Crichton Books 1
Vintage 1
Vintage Books 1
sqlite> .tables
AUTORS BOOKS DGRANNBOOKS LinkTable PUBLISHERS
sqlite> select BK_NAME, BOOK_ID, AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID JOIN on LINKTABLE.AUT_ID=AUTORS.AUT_ID
...> ;
Error: near "on": syntax error
sqlite> select BK_NAME, BOOK_ID, AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID JOIN on LINKTABLE.AUT_ID=AUTORS.AUT_ID;
Error: near "on": syntax error
sqlite> select BK_NAME, BOOK_ID, AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID JOIN AUTORS on LINKTABLE.AUT_ID=AUTORS.AUT_ID;
Error: no such column: BOOK_ID
sqlite> select BK_NAME, BK_ID, AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID JOIN AUTORS on LINKTABLE.AUT_ID=AUTORS.AUT_ID;
Error: ambiguous column name: BK_ID
sqlite> select BK_NAME, BK_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID
...> ;
Error: ambiguous column name: BK_ID
sqlite> select BK_NAME, BK_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID;
Error: ambiguous column name: BK_ID
sqlite> select BK_NAME, LINKTABLE.AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID;
BK_NAME AUT_ID
--------------------------------------------------
----------------------------------------
Killers of the Flower Moon:The Osage Murders and t 1
The Lost City of Z: A Tale of Deadly Obsession in 1
The C++ Standard Library: A Tutorial and Reference 2
C++ Templates: The Complete Guide (2nd Edition) 2
C++ Templates: The Complete Guide (2nd Edition) 3
The Silent Patient 4
A Long Way Gone: Memoirs of a Boy Soldier 6
Are You There God? It's Me, Margaret 5
sqlite> select BK_NAME, LINKTABLE.AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID join autors on linktable.aut_id=autors.aut_id;
BK_NAME AUT_ID
--------------------------------------------------
----------------------------------------
Killers of the Flower Moon:The Osage Murders and t 1
The Lost City of Z: A Tale of Deadly Obsession in 1
The C++ Standard Library: A Tutorial and Reference 2
C++ Templates: The Complete Guide (2nd Edition) 2
C++ Templates: The Complete Guide (2nd Edition) 3
The Silent Patient 4
A Long Way Gone: Memoirs of a Boy Soldier 6
Are You There God? It's Me, Margaret 5
sqlite> select BK_NAME, LINKTABLE.AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID join AUTORS on linktable.aut_id=autors.aut_id;
BK_NAME AUT_ID
--------------------------------------------------
----------------------------------------
Killers of the Flower Moon:The Osage Murders and t 1
The Lost City of Z: A Tale of Deadly Obsession in 1
The C++ Standard Library: A Tutorial and Reference 2
C++ Templates: The Complete Guide (2nd Edition) 2
C++ Templates: The Complete Guide (2nd Edition) 3
The Silent Patient 4
A Long Way Gone: Memoirs of a Boy Soldier 6
Are You There God? It's Me, Margaret 5
sqlite> select BK_NAME, LINKTABLE.AUT_ID from BOOKS join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID from autors join linktable
linktable.aut_id=autors.aut_id;
Error: near "from": syntax error
sqlite> select BK_NAME, LINKTABLE.AUT_ID, autors.aut_name from from BOOKS join
LINKTABLE on BOOKS.BK_ID=LINKTABLE.BK_ID join autors linktable
linktable.aut_id=autors.aut_id;
Error: near "from": syntax error
sqlite> select BK_NAME, LINKTABLE.AUT_ID, autors.aut_name from BOOKS join
LINKTABLE on BOOKS.BK_ID=LINKTABLE.BK_ID join autors
linktable.aut_id=autors.aut_id;
Error: near ".": syntax error
sqlite> select BK_NAME, LINKTABLE.AUT_ID, autors.aut_name from BOOKS join
LINKTABLE on BOOKS.BK_ID=LINKTABLE.BK_ID join autors on
linktable.aut_id=autors.aut_id;
BK_NAME AUT_ID
AUT_NAME
--------------------------------------------------
---------------------------------------- -----------
Killers of the Flower Moon:The Osage Murders and t 1
David Grann
The Lost City of Z: A Tale of Deadly Obsession in 1
David Grann
The C++ Standard Library: A Tutorial and Reference 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 3
David Vande
The Silent Patient 4
Alex Michae
A Long Way Gone: Memoirs of a Boy Soldier 6
Ishmael Bea
Are You There God? It's Me, Margaret 5
Judy Blume
sqlite> select BK_NAME, LINKTABLE.AUT_ID, autors.aut_name from BOOKS left join
LINKTABLE on BOOKS.BK_ID=LINKTABLE.BK_ID join autors on
linktable.aut_id=autors.aut_id;
BK_NAME AUT_ID
AUT_NAME
--------------------------------------------------
---------------------------------------- -----------
Killers of the Flower Moon:The Osage Murders and t 1
David Grann
The Lost City of Z: A Tale of Deadly Obsession in 1
David Grann
The C++ Standard Library: A Tutorial and Reference 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 3
David Vande
The Silent Patient 4
Alex Michae
A Long Way Gone: Memoirs of a Boy Soldier 6
Ishmael Bea
Are You There God? It's Me, Margaret 5
Judy Blume
sqlite> select BK_NAME, LINKTABLE.AUT_ID, autors.aut_name from BOOKS left join
LINKTABLE on BOOKS.BK_ID=LINKTABLE.BK_ID left join autors on
linktable.aut_id=autors.aut_id;
BK_NAME AUT_ID
AUT_NAME
--------------------------------------------------
---------------------------------------- -----------
Killers of the Flower Moon:The Osage Murders and t 1
David Grann
The Lost City of Z: A Tale of Deadly Obsession in 1
David Grann
The C++ Standard Library: A Tutorial and Reference 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 2
Nicolai M.
C++ Templates: The Complete Guide (2nd Edition) 3
David Vande
The Silent Patient 4
Alex Michae
A Long Way Gone: Memoirs of a Boy Soldier 6
Ishmael Bea
Are You There God? It's Me, Margaret 5
Judy Blume
sqlite> SELECT BK_NAME, COUNT(AUT_NAME) FROM autors LEFT JOIN BOOKS ON BOOKS.PB_ID
= PUBLISHERS.PB_ID GROUP BY BK_NAME;
Error: no such column: PUBLISHERS.PB_ID
sqlite> select BK_NAME, autors.aut_name from BOOKS left join LINKTABLE on
BOOKS.BK_ID=LINKTABLE.BK_ID left join autors on linktable.aut_id=autors.aut_id;
BK_NAME AUT_NAME
--------------------------------------------------
----------------------------------------
Killers of the Flower Moon:The Osage Murders and t David Grann
The Lost City of Z: A Tale of Deadly Obsession in David Grann
The C++ Standard Library: A Tutorial and Reference Nicolai M. Josuttis
C++ Templates: The Complete Guide (2nd Edition) Nicolai M. Josuttis
C++ Templates: The Complete Guide (2nd Edition) David Vandevoorde
The Silent Patient Alex Michaelides
A Long Way Gone: Memoirs of a Boy Soldier Ishmael Beah
Are You There God? It's Me, Margaret Judy Blume
sqlite> SELECT BK_NAME, COUNT(AUT_NAME) FROM autors LEFT JOIN LINKTABLE on
BOOKS.BK_ID= BOOKS ON BOOKS.PB_ID = PUBLISHERS.PB_ID GROUP BY BK_NAME;
Error: near "ON": syntax error
sqlite>

select BK_NAME, autors.aut_name from BOOKS left join LINKTABLE on


BOOKS.BK_ID=LINKTABLE.BK_ID left join autors on linktable.aut_id=autors.aut_id;

дома дописать подсчет количества книг у автора и количество авторов в книге.

You might also like