On 11/02/2020 16.54, Ammammata wrote:
let me make an example
consider a database with over one million of records, i.e. all nba
boxscores since 1940-something
consider just a few fields, i.e.
playerID, gameID, date, points, rebounds
records are sorted by gameID
I apply a couple of filters, i.e. points >= 30 and rebounds >=20
how would you make a query to get the "streaks" of consecutive games
for one player that fit the filters?
How can I check if between two filtered records there is at least one that doesn't match the criteria and breaks the streak?
If you want to do it in the database instead of in the presentation
layer, then you need to look at cursors and temp tables
https://dev.mysql.com/doc/refman/8.0/en/cursors.html
https://dev.mysql.com/doc/refman/8.0/en/create-temporary-table.html
Store the longest streak in the temp table, if you find a longer one you
just delete the current "longest one".
Just keep in mind that this will take time to calculate, so do not do
this for every request, you may make a job that executes a procedure
that makes the calculation and then stores the result to a table, which
then is used to display the longest streak.
A popular method is to do an check if the current streak is longer than
the longest one when adding a new entry for the "boxer", as this will
happen less frequently than someone looking for the information.
If you have MariaDB instead of MySQL, you can use the graphdatabase to
make the calculation, as it would be faster on this kind of queries (the
draw back with the MariaDB is that the graphdatabase is just in memory),
for more permanent solution you would need to look at neo4j or similar,
which stores the database to disk.
Still simplest is to use the presentation layer for figuring things out
and I doubt your teacher will deduct points from your assignment for that.
--
//Aho
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)