Past paper for physics
Past paper for physics
Data Types
• Table fields are represented by columns in a table
• There are 5 fields in the customer table below
o These include CustomerID, FirstName, LastName, DOB and
PhoneNumber
SQL
• Records in a database can be searched and data can be manipulated
using Structured Query Language (SQL)
• SQL statements can be written to query the data in the database and extract
useful information
• SQL statements follow this structure:
o SELECT the fields you want to display
o FROM the table/tables containing the data you wish to search
o WHERE the search criteria
Example
FROM Movie
WHERE Rating>8.4;
• The two fields - Name and Rating have been extracted from the Movie table
and then the records have been filtered by Rating
• This example uses the > operator to search for records where the rating
is greater than 8.4
• There are several other comparison operators which can be used to create
the filter criteria in the WHERE line of a SQL query
Example
SELECT Name,Rating
FROM Movie
• The two fields Name and Rating have been extracted from the Movie table
and the records have been filtered by both Genre and Certificate
• This query uses the AND logical operator to include multiple criteria in the
WHERE line of the SQL query
• Another logical operator which can be used in the WHERE statement is OR
o For example, WHERE Genre=”Comedy” OR Genre=”Family”
ORDER BY
• You can enter a fourth line to the statement using the ORDER BY command,
followed by ASC or DESC
o If you enter ASC the results of the query will be sorted
in ascending order
o If you enter DESC the results of the query are sorted
in descending order
Example
FROM Movie
• The query has returned four fields and all records because there were no
WHERE criteria. The records are sorted by Name alphabetically
o If numbers are sorted in ascending order they go from the lowest
number at the top of the table to the highest number at the bottom
o Descending order is the highest number to the lowest
Example
SELECT SUM(QuantityInStock)
FROM ProductTable;
• This query will add up all of the numbers in the QuantityInStock field
o The result of this query would be 25
Example
SELECT COUNT(*)
FROM ProductTable
WHERE Price>2;
• This query will count all the records with a price greater than 2
o The result of this query would be 3
o This is because there are three products with a price greater than £2
(Chips, Beans, Bananas)