text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
but this SQLite prompt is a very direct way
1,302.22
2.22
of just being able to write a query very quickly
1,304.44
2.19
and see the results of that query.
1,306.63
2.835
So it turns out, there are other types of queries we can run as well.
1,309.465
2.875
So we'll take a look at some others.
1,312.34
1.5
We don't just need to say where something equals something else.
1,313.84
3.29
Other types of Boolean expressions are allowed as well.
1,317.13
2.76
So I could say something like SELECT * from flights
1,319.89
2.91
where duration is greater than 500.
1,322.8
2.41
Where the idea here is let's look at the duration column.
1,325.21
2.81
It's an integer, so we can do arithmetic expressions on these values.
1,328.02
4.11
I can take a value and see if it's greater than 500 or not.
1,332.13
3.5
When I do that, what I get back is all of the rows that have
1,335.63
2.62
a duration that's greater than 500.
1,338.25
2.34
I can begin to query not just on whether one value equals
1,340.59
2.97
another value, but also other types of comparisons as well.
1,343.56
3.96
Much as in Python, as when we had Boolean expressions in Python,
1,347.52
3.12
I could join multiple Boolean expressions together
1,350.64
2.67
using words like AND and OR.
1,353.31
2.4
SQL has the same type of thing in its own query syntax, too.
1,355.71
3.6
I could say something like SELECT * from flights where duration is greater than
1,359.31
3.99
500 AND destination= "Paris."
1,363.3
3.06
As you might logically intuit this means,
1,366.36
2.1
this means get me all the flights that are going to Paris
1,368.46
2.97
and that take longer than 500 minutes.
1,371.43
2.16
It turns out there's only one such row inside this table that
1,373.59
3.27
satisfies both of those constraints.
1,376.86
2.97
Of course, instead of using AND I could've also
1,379.83
2.13
used OR to get a different query where now I'm looking for all of the flights
1,381.96
6.12
longer than 500 minutes or the destination is Paris.
1,388.08
3.81
So as long as either of those conditions are met, I'm going to get results back.
1,391.89
3.93
So what I get back are some of the rows where the destination is Paris,
1,395.82
3.36
some rows where the destination isn't Paris,
1,399.18
2.01
but the duration is more than 500 minutes,
1,401.19
2.74
and of course any row that satisfies both of these constraints.
1,403.93
3.23
In particular, flight id number 2.
1,407.16
2.7
That gets resulted as well when I run this particular query on this table.
1,409.86
6.028
There are other types of queries I can perform in addition to that.
1,415.888
2.792
So I can say something like SELECT * from flights
1,418.68
2.37
where origin is in-- and then in parentheses-- in "New York"
1,421.05
2.97
comma "Lima" to say, check if the origin is in this sequence of possible values.
1,424.02
4.23
The sequence of New York and Lima, as long as it is one of those two, then
1,428.25
4.05
I want for the results to come back.
1,432.3
1.74
So then you'll get back rows that have an origin of New York, rows
1,434.04
3.36
that have an origin of Lima, as well.
1,437.4
1.68
So you can begin to construct more sophisticated queries that
1,439.08
3.33
are able to check for whether an origin is in a list of possible values
1,442.41
3.36
or even if it matches a particular pattern.
1,445.77
2.97
That maybe you know that one of the columns looks a certain way
1,448.74
2.7
or is formatted according to a particular structure,
1,451.44
2.167
but you don't know exactly what the value is.
1,453.607
2.943
I could run a query like SELECT * from flights where origin--
1,456.55
3.98
not equals-- but where origin is like--
1,460.53
3.36
and then in quotation marks, I have a bit of a strange expression "%a%"
1,463.89
5.49
This percent stands for a wild card.
1,469.38
3.07
And this time the wild card is looking at the values of a particular column.
1,472.45
3.48
In this case, the value of the origin column, meaning the percent
1,475.93
3.2
stands for zero or more characters, no matter what those characters are.
1,479.13
3.81
We're looking for some number of characters-- maybe zero maybe more--
1,482.94
3.09
followed by an A, followed by some other number of characters--
1,486.03
3.06
maybe zero maybe more.
1,489.09
2.17
And ultimately what this query is going to do
1,491.26
2.39
is look inside of the flights table and get back to me
1,493.65
2.97
all of the results where there is an A the origin.
1,496.62
3.54
As long as there is an A in the origin column,
1,500.16
2.13
doesn't matter if there are characters before it or characters after it,
1,502.29
3
all of the rows that come back are going to be the rows that
1,505.29
2.82
just so happened to have an A in it.
1,508.11
2.88
So lots of ways we can begin to run SELECT queries.
1,510.99
2.37
And there are even additional functions you can add to your select queries
1,513.36
3.083
as well.
1,516.443
0.757
If instead of just selecting the values of columns,
1,517.2
2.46
I want to compute the average duration of a particular category of flights,
1,519.66
3.828
or I want to count how many flights that are coming out of New York, or I
1,523.488
3.042
want to find the longest flight that goes to London,
1,526.53
2.19
or the shortest flight that goes to London,
1,528.72
1.86
or I want to add up all of the durations for a whole bunch of flights.
1,530.58
2.917
Maybe there are flights that are connected to each other
1,533.497
2.333
and I want to add up the total travel time that might take.
1,535.83
2.61
SQL has a number of built-in functions that
1,538.44
2.31
allow us to perform these sorts of calculations, as well.
1,540.75
3.663
So a couple of different SQL commands we've now taken a look at.
1,544.413
2.667
We've taken a look at Create Table that allows us to create a new table.
1,547.08
3.87
INSERT that lets us add data to a table.
1,550.95
2.82
SELECT, which lets us take data inside of the table and retrieve it.
1,553.77
3.727
But, of course, often when we're dealing with databases,
1,557.497
2.333
the data doesn't just get added.
1,559.83
1.44
The data changes in some way.
1,561.27
1.9
So we also need some way of being able to update data after it's already
1,563.17
3.53
inside of our database.
1,566.7
2.14
There's another query for that, which is an Update command that we
1,568.84
2.9
can execute on our database.
1,571.74
1.92
And that command looks something like this.
1,573.66
1.86
Again displayed on multiple lines, but you could put this entirely just on one
1,575.52
3.53
line.
1,579.05
0.5
SQL doesn't really care if you add line breaks.
1,579.55
2.503
It just knows that when it sees a semicolon at the end of the command,
1,582.053
2.917
that is the end of this particular command.
1,584.97
3.09
But here what I've said is used the Update keyword
1,588.06
2.85
to say I would like to update a table.
1,590.91
2.243