4. A Symptoms checker - Disease
B Metabolic engineering
C Cancer Neoantigens
Familienaam Voornaam E-mail Opleidingsprogramma
Davey Lucas Lucas.Davey@UGent.be C CMBIOISB
David Sven Sven.David@UGent.be B IMCELB
Engelen Yanou Yanou.Engelen@UGent.be ? IMCELB
Ezquerro Marrodán Elsa Elsa.EzquerroMarrodan@UGent.be C IXGAEX
Georis Raphaël Raphael.Georis@UGent.be B IMCELB
Gilis Jeroen Jeroen.Gilis@UGent.be B CMBIOISB
Lashkari Samira Samira.Lashakri@UGent.be A CMBIOISB
Recer Karmen Karmen.Recer@UGent.be C IXGAEX
Schindfessel Cédric Cedric.Schindfessel@UGent.be B IMCELB
Silva Marta Marta.Silva@UGent.be B CMBIOISB
Silva Meneses Rodrigo Rodrigo.Meneses@UGent.be C CMBIOISB
Strybol Pieter-Paul PieterPaul.Strybol@UGent.be B/C CMBIOIBE
Taelman Steff Steff.Taelman@UGent.be A CMBIOIBE
Tóth Máté István MateIstvan.Toth@UGent.be C EXGAEX
Toulmé Coralyne Coralyne.Toulme@UGent.be C IXGAEX
Van hoyweghen Sergej Sergej.Vanhoyweghen@UGent.be ? IMCELB
Willems Thomas Thomas.Willems@UGent.be ? IMCELB
Wojciulewitsch Coralie Coralie.Wojciulewitsch@UGent.be A IMCELB
Yekimov Illya Illya.Yekimov@UGent.be A IMCELB
6. Selecta Statement (General)
Select componentsb (MySQL version 4.0.X)
1. Select (required)
2. Expression (required)
3. From Table (Only optional if table data is
not used)
4. Where Condition (optional)
5. Group By (optional)
6. Having (optional)
7. Order By (optional)
8. Limit (optional)
aWords listed in blue above are key (reserved) words in MySQL, except
“Expression”
bThere are many more components in the select statement, but only the most
common are discussed
7. Select
• Is a MySQL keyword at the
beginning of a Structured Query
Language (SQL) statement or more
simply a query that retrieves data
from a database.
• It can be used in conjunction with the
MySQL command insert, replace,
and create table.
8. Expression
The “expression”
1. Selects which columns (by column name)
will be retrieved
2. Apply MySQL functions on the columns
of data
Examples—
* (Selects all columns in a table)
temperature * 1.8 + 32a
dt, temperature, relative_humidityb
aApply arithmetic operations on a column
bChoose multiple columns in single query
Note: columns are in green, tables are in red,
MySQL functions are in magenta.
9. Expression Cont
More Examples--
-1 * speed * sin( direction * pi() / 180 )c
-1 * speed * cos( direction * pi() / 180 )
as Vd
avg(temperature)e
tableX.temperature,
tableY.temperaturef
cCan use built in mathematical functions.
dThe ‘as’ keyword can be used to set the output column name.
eCan retrieve a statistical value from rows of data. Must be used with ‘group by’.
fThe select can retrieve or make relationships from multiple tables from a single
query. Note the ‘.’ that separates the table name and column name.
10. From
Tells MySQL which table(s) to select
froma
aIf multiple tables are used in the
expression, they all must be listed
here seperated by a ‘,’
11. Where
Sets the condition of which rows to select. Useful
for eliminating unwanted data from your results.
Conditional
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
= Equals
!= Not equals
Logical
and True if both are true
or True if only one is true
() Useful for grouping or
ordering multiple logical
statements
String pattern matching
like a MySQL keyword in-between column and pattern
% a wildcard that matches all instances in a string
_ a wildcard that matches only the character location
12. Group By
Aggregates rows by distinct values in the columns
listed in the ‘group by’ when using statistical
functions (e.g., avg, std, max, min, sum, count, etc.)
Example--
group by site_ida
group by site_id, month(dt)b
aSingle column
bMultiple columns and apply functions on a column
13. Having
Similar to where, except that it must follow
‘group by’ group, and only eliminates results
after the results have been aggregated. See
where for more details.
14. Order By
• Orders the result rows defined by the columns in the
‘order by’ group
• The keyword asc (ascending) and desc (descending)
to change the order of the result rows, and is always
at the end of the order by component. desc is the
default.
Examples—
order by dt
order by dt, site_ida
aThe first column is ordered first, second column is ordered second
on the ordering of the first column, and so on
15. Order By Example
mysql>select … order by site_id, month asc
site_id month ave_temp
1 1 32.3
1 2 40.2
1 3 49.5
2 1 35.6
2 2 41.3
2 3 53.5
16. Limit
Limits the number of rows from the result set
limit row_counta
limit offset, row_countb
aStarts at the first row
bStarts at the offset row
17. Outerjoins
Explicit joins in SQL:
Product(name, category)
Purchase(prodName, store)
Same as:
But Products that never sold will be lost !
SELECT Product.name, Purchase.store
FROM Product JOIN Purchase ON
Product.name = Purchase.prodName
SELECT Product.name, Purchase.store
FROM Product, Purchase
WHERE Product.name = Purchase.prodName
18. Outer Joins
• Left outer join:
– Include the left tuple even if there’s no
match
• Right outer join:
– Include the right tuple even if there’s no
match
• Full outer join:
– Include the both left and right tuples even
if there’s no match
20. Modifying the Database
Three kinds of modifications
• Insertions
• Deletions
• Updates
Sometimes they are all called “updates”
21. Insertions
General form:
Missing attribute NULL.
May drop attribute names if give them in order.
INSERT INTO R(A1,…., An) VALUES (v1,…., vn)
INSERT INTO Purchase(buyer, seller, product, store)
VALUES (‘Joe’, ‘Fred’, ‘wakeup-clock-espresso-machine’,
‘The Sharper Image’)
Example: Insert a new purchase to the database:
22. Insertions
INSERT INTO PRODUCT(name)
SELECT DISTINCT Purchase.product
FROM Purchase
WHERE Purchase.date > “10/26/01”
The query replaces the VALUES keyword.
Here we insert many tuples into PRODUCT
23. Insertion: an Example
INSERT INTO Product(name)
SELECT DISTINCT prodName
FROM Purchase
WHERE prodName NOT IN (SELECT name FROM Product)
name listPrice category
gizmo 100 Gadgets
camera - -
24. Deletions
DELETE FROM PURCHASE
WHERE seller = ‘Joe’ AND
product = ‘Brooklyn Bridge’
Factoid about SQL: there is no way to delete only a single
occurrence of a tuple that appears twice
in a relation.
Example:
25. Updates
UPDATE PRODUCT
SET price = price/2
WHERE Product.name IN
(SELECT product
FROM Purchase
WHERE Date =‘Oct, 25, 1999’);
Example:
26. Indexes
REALLY important to speed up query processing time.
Suppose we have a relation
Person (name, age, city)
Sequential scan of the file Person may take long
SELECT *
FROM Person
WHERE name = “Smith”
27. • Create an index on name:
• B+ trees have fan-out of 100s: max 4 levels !
Indexes
Adam Betty Charles …. Smith ….
29. Creating Indexes
Indexes can be created on more than one attribute:
CREATE INDEX doubleindex ON
Person (age, city)
SELECT *
FROM Person
WHERE age = 55 AND city = “Seattle”
SELECT *
FROM Person
WHERE city = “Seattle”
Helps in:
But not in:
Example:
30. Creating Indexes
Indexes can be useful in range queries too:
B+ trees help in:
Why not create indexes on everything?
CREATE INDEX ageIndex ON Person (age)
SELECT *
FROM Person
WHERE age > 25 AND age < 28
31. Views are relations, except that they are not physically stored.
For presenting different information to different users
Employee(ssn, name, department, project, salary)
Payroll has access to Employee, others only to Developers
CREATE VIEW Developers AS
SELECT name, project
FROM Employee
WHERE department = “Development”
32. A Different View
Person(name, city)
Purchase(buyer, seller, product, store)
Product(name, maker, category)
We have a new virtual table:
Seattle-view(buyer, seller, product, store)
CREATE VIEW Seattle-view AS
SELECT buyer, seller, product, store
FROM Person, Purchase
WHERE Person.city = “Seattle” AND
Person.name = Purchase.buyer
33. A Different View
SELECT name, store
FROM Seattle-view, Product
WHERE Seattle-view.product = Product.name AND
Product.category = “shoes”
We can later use the view:
34. 34
Types of Views
• Virtual views:
– Used in databases
– Computed only on-demand – slower at
runtime
– Always up to date
• Materialized views
– Used in data warehouses
– Precomputed offline – faster at runtime
– May have stale data
36. For the project I suggest to take the following
steps (individual or in group - maybe setup a
collaborative tool like slack)
1. What it is about ? What do you want to
achieve ? For who ?
2. identify information resources - think about
a basic data-model
3. Draw (mockup) an interface, don't be
constrained by technical consideration - think
ouside the box:)