How can I select data lying within a certain span of time?


#1

Question

In the context of this code challenge, how can I select data lying within a certain span of time?

Answer

In this exercise, you need to select data lying within the full span of time. This is somewhat of a trick question, as you do not actually need to add some WHERE condition to do this because without specifying a certain time span it will select all of them regardless of the value.

If you did want to select some specific time range, between specific years or dates, you can use the WHERE clause with BETWEEN. For example, to obtain the data lying within a span of years, you can do the following,

WHERE year BETWEEN 1880 AND 1900

And, if you wish to obtain data within a span of dates, you can do the following for example,

WHERE date BETWEEN `1880-01-01` AND `1900-12-31`