5. 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
6. 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.
7. 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.
8. 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.
9. 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 ‘,’
10. 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
11. 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
12. 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.
13. WHERE and HAVING
• WHERE refers to the
rows of tables, and so
cannot use aggregate
functions
• HAVING refers to the
groups of rows, and so
cannot use columns
which are not in the
GROUP BY
• Think of a query being
processed as follows:
• Tables are combined
• WHERE clauses
• GROUP BY and
Aggregates
• Column selection
• HAVING clauses
• ORDER BY
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. JOINS
Explicit joins in SQL:
Product(name, category)
Purchase(prodName, store)
Same as:
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
19. Modifying the Database
Three kinds of modifications
• Insertions
• Deletions
• Updates
Sometimes they are all called “updates”
20. 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:
21. 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
22. 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 - -
23. 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:
24. Updates
UPDATE PRODUCT
SET price = price/2
WHERE Product.name IN
(SELECT product
FROM Purchase
WHERE Date =‘Oct, 25, 1999’);
Example:
25. 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”
26. • Create an index on name:
• B+ trees have fan-out of 100s: max 4 levels !
Indexes
Adam Betty Charles …. Smith ….
28. 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:
29. 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
30. 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”
31. 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
32. 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:
33. 33
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
37. # rsid chromosome position genotype
rs4477212 1 82154 AA
rs3094315 1 752566 AA
rs3131972 1 752721 GG
rs12124819 1 776546 AG
rs11240777 1 798959 GG
rs6681049 1 800007 CC
rs4970383 1 838555 AC
rs4475691 1 846808 CT
rs7537756 1 854250 AG
rs13302982 1 861808 GG
rs1110052 1 873558 GT
rs2272756 1 882033 AG
rs3748597 1 888659 CC
rs13303106 1 891945 AG
rs28415373 1 893981 CC
rs13303010 1 894573 AA
rs6696281 1 903104 CC
rs28391282 1 904165 GG
rs2340592 1 910935 AG
rs13303118 1 918384 GT
rs6665000 1 924898 AC
38.
39.
40.
41.
42.
43.
44.
45. Chromsome 12
• Less than 1% of the population is
able to survive on six hours of
sleep and show minimal
impairment (relates to the
BHLHE41/DEC2 gene).
46. Chromosome I
March 19, 2019 46
Chromosome l contains more
genetic information than any other
chromosome: almost 10% of the
entire human genome (240 Mb –
3000 Genes).
149 genetic diseases related to this
chromosome have been identified;
prostate cancer is one of them, the
most frequent form of cancer
affecting males.
47. Key observation by Levine and Stetson in 1939 that delivery of stillborn
fetus and adverse reaction in mom to blood transfusion from father were
related.
Syndrome in fetus is now referred to as hemolytic disease of the fetus and
newborn (HDFN).
Syndrome had complicated pregnancies for decades causing severe jaundice and
fetal death, “erythroblastosis fetalis”.
Erythroblastosis fetalis (HDN) linked with Anti-Rh by Levine in 1941.
Rh system IDENTIFIED by Landsteiner and Wiener in 1940.
Immunized animals to Rhesus macaque monkey RBCs.
Antibody agglutinated 100% of Rhesus and 85% of human RBCs.
Reactivity paralleled reactivity of sera in women who delivered infant suffering
from hemolytic disease.
Later antigen detected by rhesus antibody and human antibody established to
be dissimilar but system already named.
March 19, 2019 47
Rh+/Rh-, History
48. D antigen, after A and B, is the most important RBC antigen in
transfusion practice.
Individuals who lack D antigen DO NOT have anti-D.
Antibody produced through exposure to D antigen through
transfusion or pregnancy.
Immunogenicity of D greater than that of all other RBC
antigens studied.
Has been reported that 80%> of D neg individuals who receive
single unit of D pos blood can be expected to develop immune
anti-D.
Testing for D is routinely performed so D neg will be transfused
with D neg.
March 19, 2019 48
Rh+/Rh-
Clinical Significance
49. Rh+/Rh-
The genes that determines the blood’s Rh factor appears to be the human genome’s oldest and most
active gene. The Rh blood group system is one of the most complex of human beings, and it is the
second in terms of importance in the field of blood transfusions — coming in just behind the ABO blood
group system.
• The Rh factor is determined by the presence or absence of the D antigen on the cell membranes of
the red blood cells.
• The Rh factor is always analyzed in pregnant women, blood donors, and recipients of blood
• People who are Rh positive (Rh+) have the D antigen, while those who are Rh negative (Rh-) lack it.
If, by accident, Rh+ blood enters the bloodstream of a Rh- individual, the immune system of the Rh-
individual will produce specific antibodies that can cause a dangerous immune response.
• The RhD and RhCE genes, which encode the Rh blood group antigens, are located on chromosome
1. The first Rhesus gene, the RHCE gene, was discovered in 1990. The RHD gene was found two years later,
and the total deletion of this gene ascertained as the cause of the European D negative phenotype. More
than 170 alleles have been found on the RHD gene since.
The genetics of the Rhesus blood group system
March 19, 2019 49
50. March 19, 2019 50
Most mammals only have one RH gene,
whose position corresponds to the
human RHCE gene. The RHD gene arose from
the duplication of an ancestral RH gene
during mammalian evolution.
An RHD deletion occurred during the
evolution of hominids, so that many modern
humans completely lack the RHD gene. This
haplotype is the leading cause of the D
negative phenotype worldwide.
Rh+/Rh-
51. March 19, 2019 51
The Rhesus protein in the erythrocyte
membrane
Both Rhesus proteins show 417 amino
acids, shown here as circles. Mature
proteins in the membrane lack the first
amino acid. The amino acid substitutions
which distinguish the RhD from the RhCE
protein are shown in yellow, with the
four amino acids which code for the C
antigen in green and the one which
codes for the E antigen in black. The
single amino acid substitutions which
code for partial D are in blue, those
which code for weak D are in red. The
mutations, identified by the Ulm group,
are in light blue and orange.
The clinically essential difference between Rhesus
positive and Rhesus negative hinges on the presence or
absence of the RhD protein in the erythrocyte membrane
(D positive resp. D negative).
Rh+/Rh-
52. Genome Evolution
March 19, 2019 52
Deletion of the RHD gene
Deletion of the RHD gene resulted from
recombination between an upstream and a
downstream Rhesus box on two different
chromosomes. This is termed an unequal
crossover. When the two crossed strands
separate (from A over the recombination site
to B), the DNA at the RH gene site completely
lacks the RHD gene (C). This haplotype (C)
occurs in about 41% of the population. An
individual homozygous for this haplotype
(about 17% are) is D-negative.
53. ACTA1
Estimating Muscle Force
Although the information provided by the
sensory receptors located in the muscles may
be perceived subconsciously, it does
allow us to make important calculations
information about the length of the muscle,
how rigid it is and the
speed with which it changes its state enables
the nervous system to
control the general position of the body. This
data is provided by two
types of sensory receptors. The first type is
located in the muscle itself
and provides information about muscle length
and speed with which it can change position.
The other receptors are found in the tendons
and
detect tension and changes.
55. Human Gene Map
for Performance
March 19, 2019 55
214 autosomal gene entries and quantitative trait loci, 7 on the X chromosome
and 18 mitochondrial genes
58. Next Week – Status update
• Show database
• Show how database will be used
• Which external database will be used
• At least 3 interesting locus on the chromosome and
related traits
• Main goal: learn from each other approach, share
some resources on github
March 19, 2019 58