Y12 CS - Week 24 - Learning Plan
Y12 CS - Week 24 - Learning Plan
Please do now!
How many rows the table have?
How many columns does the table have?
What is the data type of the values stored under “Height”?
Database
• A database is a structured way to store data so that it can be retrieved
using queries
Table name Field Field name
Animals
Table Animal Length TopSpeed
Brown bear 2.48 21.7
Elk 1.4 45.1
Record Lion 2.8 49.7
Pig 0.9 10.9
8.3 Data Definition Language
(DDL) and Data Manipulation
Language (DML)
To Do List
SQL
• SQL (pronounced S-Q-L or Sequel) stands for Structured Query
Language
• It is a declarative language used for querying and updating tables in a
relational database
• It can also be used to create tables
• You can create SQL statements in a programming language such as
Python to access and manipulate a database
Activity
• Go to: https://sqliteonline.com/
CREATE TABLE Dogs (DogID INTEGER PRIMARY KEY, Name VARCHAR(20), Breed VARCHAR(20), Colour VARCHAR(20), Gender CHAR(1), Age
INTEGER);
INSERT INTO Dogs VALUES (1, "Coco", "Labrador", "Brown", 'M', 3);
INSERT INTO Dogs VALUES (2, "Milly", "Spaniel", "Black", 'F', 5);
INSERT INTO Dogs VALUES (3, "Sasha", "Retriever", "Golden", 'F', 4);
INSERT INTO Dogs VALUES (4, "Mark", "Labrador", "Black", 'M', 3);
INSERT INTO Dogs VALUES (5, "Marlee", "Retriever", "Golden", 'F', 2);
INSERT INTO Dogs VALUES (6, "Alfie", "Spaniel", "Brown", 'M', 6);
INSERT INTO Dogs VALUES (7, "Georgie", "Labrador", "Black", 'F', 5);
• Insert three animals into the table
Data types
Data type Description Example
CHARACTER Char string of fixed length ProductCode CHARACTER
Which products will be selected by the following SQL statement? In what order?
Results
productID productName subject price
p47 Database Comp Science £5.00
p36 Programming Comp Science £5.00
Activity
Using a wild card
tblProduct
productID productName subject level price
p24 Equations Maths 2 £12.00
p36 Programming Comp Science 4 £5.00
p47 Database Comp Science 4 £5.00
p54 Hardware Computing 3 £6.00
• You can use a “wild card” * to mean “all” or “one or many characters”
SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*”
• “LIKE” is used to search for a pattern
Activity
• Write a SQL query to: Show the values of all fields in the table.
Activity
Write a query to select the field values of any record from the “demo”
table where the value of the Name field starts with “Crea”.
Hint: Use LIKE and the % wild card, which means 0 or more characters.
Activity p36
p47
Programming
Database
Comp Science
Comp Science
4
4
£5.00
£5.00
p54 Hardware Computing 3 £6.00
SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*” AND level = 4
Use of semi-colon
• Some database systems require a semicolon at the end of each SQL
statement
• A semicolon is the standard way to separate each SQL statement
• Do NOT put a semicolon at the end of each line, only the last line
SELECT *
FROM tblProduct
WHERE subject LIKE “Comp*” AND level = 4;
Note: In your exam, use a semi-colon. Past papers use them too.
Activity
1. What is the name of the
table?
2. How many records does the
table have?
3. How many columns does the
table have?
4. Which attribute is the
primary key?
5. What is the data type of the
values for Price?
6. What is the data type for the
values for Name?
Sorting: the ORDER BY keyword
• ORDER BY allows a query to sort data by ascending or descending order
• For ascending order
SELECT *
FROM members
ORDER BY Surname ASC
• For descending order
SELECT *
FROM members
ORDER BY Surname DESC
Activity
MemberID FirstName Surname Gender Town
1 David Johnson M Ipswich
2 Christine Bates F Woodbridge
3 Jasmine Hamid F Ipswich
4 Peter Okello M Colchester
5 Stephen Hines M Woodbridge
• COUNT is number of non-null field values. Sum is the total of field values.
SELECT COUNT(Quantity)
FROM Receipts
Result: COUNT(Quantity) Receipts
4
ReceiptID Product Quantity Cost
1 Apples 6 2.20
• Find all animal names and weights that are over 1000 kg
• AI = computer simulating
human intelligence
• ML = computer improves at a
task (i.e., “learns”)
• WITH experience, and
• WITHOUT explicit
programming
Characteristics of AI systems
• There are a number of characteristics of AI including:
• Collection of data
• Rules for using the data
• The ability to reason
• The ability to learn or adapt
• Nowadays the most common way is to let the system learn the rules
by itself, but before we would have domain experts create the rules
Rules
• Rules are used by AI to determine the answers to questions
• They may be programmed by a human or ‘discovered’ by machine learning
• Create a set of rules that determines if a photo shows someone to be happy
or sad
Rules
• Happy:
• Teeth are showing; crease around edges of lips; eyes are wider; edges of
mouth raised
• Sad:
• Eyes more closed; mouth bends down at edges; possibly tears; teeth not
showing
Reasoning
• Artificial intelligence is able to use reasoning to find out new
information based on the rules it is given
• A deductive reasoning example:
• Humans eat vegetables
• Zach is human
• Reasoning deduces: Zach eats vegetables
Expert systems
• What patterns do you think it will find from the following data?
1 8 1 300 25 9 Fish
2 7 2 250 20 8 Fish
3 5 20 400 30 4 Chips
4 8 1 150 35 7 Fish
5 9 1 200 25 8 Fish
6 6 15 200 20 5 Chips
Machine learning rules
• The machine learning will also give weights to the importance of each
property
• For instance, a small weight may be given to the Weight property if it is high
• A large weight will be given to the number of items as the difference is so big
Item number Golden intensity Number of items Weight Temp Crispness Food item
1 8 1 300 25 9 Fish
2 7 2 250 20 8 Fish
3 5 20 400 30 4 Chips
4 8 1 150 35 7 Fish
5 9 1 200 25 8 Fish
6 6 15 200 20 5 Chips
Activity
Fill in the gaps with the words beneath.