WDI2
WDI2
Databases & ML 5
© Jerzy Nawrocki, Introduction to Computing
Riddle
Introduction to Computing Introduction to Computing
Result
Solution
Useful functions
Databases & ML 10
© Jerzy Nawrocki, Introduction to Computing
Distinct items
Workers
Key FName SName
20 Konrad Ciszak
First names of the workers? 21 Piotr Miklosik
22 Konrad Nawrocki
23 Leszek Pacholski
SELECT FName
FROM Workers FName
ORDER BY FName ASC; Konrad
Konrad
Group of rows:
the same value Leszek
of a given attrib. Piotr
Databases & ML (71) Databases & ML (72)
Databases & ML 12
© Jerzy Nawrocki, Introduction to Computing
Databases & ML 13
© Jerzy Nawrocki, Introduction to Computing
CREATE an empty table with a given set of columns CREATE an empty table with a given set of columns
INSERT a row into a given table INSERT a row into a given table
UPDATE some rows of a given table UPDATE some rows of a given table
DELETE some rows of a given table DELETE some rows of a given table
SELECT (read) data from table(s) SELECT (read) data from table(s)
import sqlite3
db = sqlite3.connect('fileName')
c = db.cursor()
c.execute("SQLstatement")
db.commit()
Workers
db.close() FName SName
Olaf Ciszak
Piotr Miklosik
import sqlite3
db = sqlite3.connect('my.db') CREATE an empty table with a given set of columns
c = db.cursor()
c.execute('''create table Workers INSERT a row into a given table
(FName VARCHAR(40),
SName VARCHAR(40) UPDATE some rows of a given table
);''')
c.execute("insert into Workers values('Olaf', 'Ciszak' );") DELETE some rows of a given table
c.execute("insert into Workers values('Piotr','Miklosik');")
db.commit()
db.close()
SELECT (read) data from table(s)
Databases & ML 14
© Jerzy Nawrocki, Introduction to Computing
#include <sqlite3.h>
C #include <sqlite3.h>
C
... ...
sqlite3 *db; sqlite3 *db;
... ...
Err= sqlite3_open(fileName, &db); Err= sqlite3_open(fileName, &db);
... ...
Err= sqlite3_exec(db, query, NULL, NULL, NULL); Err= sqlite3_exec(db, query, NULL, NULL, NULL);
... ...
Err= sqlite3_close(db); Err= sqlite3_close(db);
#include <sqlite3.h>
C #include <sqlite3.h>
C
... ...
sqlite3 *db; sqlite3 *db;
... ...
Err= sqlite3_open(fileName, &db); Err= sqlite3_open(fileName, &db);
... ...
Err= sqlite3_exec(db, query, NULL, NULL, NULL); Err= sqlite3_exec(db, query, NULL, NULL, NULL);
... ...
Err= sqlite3_close(db); Err= sqlite3_close(db);
Databases & ML 15
© Jerzy Nawrocki, Introduction to Computing
?
then STOP.
2. If not: Which column to
choose?
3. What are the values in the
column?
4. Divide the table into
subtables by those values.
5. Repeat the procedure for
each subtable.
https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/ https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/
Databases & ML (103) Databases & ML (104)
Training data
1. If the data are unanimous 1. If the data are unanimous
then STOP. then STOP.
2. If not: Which column to 2. If not: Which column to
choose? choose?
3. What are the values in the 3. What are the values in the
column? column?
4. Divide the table into 4. Divide the table into
subtables by those values. subtables by those values.
5. Repeat the procedure for 5. Repeat the procedure for
each subtable. each subtable.
https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/ https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/
Databases & ML (105) Databases & ML (106)
https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/ https://automaticaddison.com/iterative-dichotomiser-3-id3-algorithm-from-scratch/
Databases & ML (107) Databases & ML (108)
Databases & ML 18