Professional Documents
Culture Documents
Okay.
So now I want to talk about, how to
interpret, or give some examples of how
to interpret, SQL statements, sort of, in
terms of relational algebra.
But, we're not going to actually write
out the plans.
But, I want to give you some experience
staring at what may seem sort of
complicated and kind of teasing out
what's actually going on here.
And so for people that have spent a lot
of time around databases and SQL, these
may or may not seem particularly
complicated, but if you're just starting
out they, they probably do.
So in this first example [SOUND] what do
we see here?
Well, what you want to look for when
you're sort of staring at something that
may seem sort of hairy is.
You know, look for the from clause here.
And so in this case, it's a little funny,
right, because we see, oops.
We see that the from clause does not have
a table name mentioned, it has a nested
query within it.
And we remember that, that's perfectly
fine because.
Of, this closure property of the, of the
underlying algebra.
We know that any relational algebra
expression, and therefore any SQL
statement, is going to return a table.
And, it operates on tables.
So, if you can operate on tables, if
you're operating on tables, and you know
you return a table, then you can sort of
chain these operations together, and you
have this nice closure property.
So, we know that we're allowed to query
derived results just like we're allowed
to query base tables.
Okay, and so in this case we're doing
derived result.
Now, well also, let's go down to the
other from clause.
Well, here we see another nested query,
another layer of nesting, again,
perfectly fine.
And one more layer, now we see this table
here.
And so where this data came from was a
sensor that was mounted underneath a
oceanographic research vessel.
That was collecting measurements of a, of
a variety of different variables.
Here a few of them are mentioned,
fluorescence, oxygen, nitrates, and
wanted to go in.
But let me, let me backtrack and come
back to that.
So hold that thought.
Popping back to the top.
This other piece of complicated logic
here.
Well, this is a particular syntax that's
available in SQL called, you know, a case
statement.
And it acts about the same way as the
case [INAUDIBLE] in other languages.
So that's not too bad, but in particular
you need to just ignore all this logic,
you can just collapse all this down and
say, well look, there is some function
that's computing leen overlap where I get
that name, well that's what I mean the.
Result of this complicated expression.
The length of the overlap.
And in fact, you know, I happen to know a
little bit about where this query came
from.
What they're working on is genetic
sequences.
And you may be able to deduce that if you
stare at this.
There's snip region which is, stands for
single nucleotide polymorphism.
And there's strain and they give you a
hint.
And bp is base pair.
And noncoding regions.
Noncoding positions gives you a bit of a
hint.
If you, if you've done any work in
biochromatics.
But if you haven't, that's okay.
The point is, len_overlap appears to be
the name of this thing.
So it's almost like there exists a
function len_overlap that involves these
attributes.
And we don't even care what's inside it.
It's just a function.
So that helps us sort of see the
underlying simplicity of this query in
this case.
Okay.
Then, back to this other complicated
expression.
Let me show you a little about what's
going on here, just 'cause I think it's
kind of a fun example.
If you break these out into these 3
conditions, and you happen to know
something about this data is coming from
you can see that what this is saying is
well look we want the start based pair
from the x table to be greater than the w