mysql - I need to find any 5 rows that match where clause and they occur "in a row" (they are neighbors) -


I have a MySQL table for an imaginary fitness app Assume that the focus on pushing the user from day-to-day Is giving up.

Training day

  id | ID_User | Date | Now, I have to figure out that the user has ever managed to do more than 5 pushups for 5 days in line.  

I know that this is probably worth bringing by all days and then making some php loops, but I wonder if this is likely to be done in plain mysql ... < In MySQL, the easiest way to use variables is to get all the sequences with 100 or more pushups in the following:

Select / p>

  grp, count (*) from numdaysinarow (select (interval-interval day) as grp, select td. * (TD. *) , (@ RN: = if (@E = ID_user, @ RN + 1 if (@I: = ID_User, 1, 1)) Training Day TN Cross Join (@ RN: = 0, @) from RN I: = null) vars where number_of_pushups> date = 100 id_user, td) td group grp;   

This observation uses that when you decrease the sequence of numbers from one To determine whether there are 5 or more days in the row, maximum () : Select grp, count (*) to numdaysinarow (select (date - a Intermittent RN day), as the grp, td * To join trainingdays TD cross (select td. *, (@rn: = if (@i = id_user, @rn + 1 if (@i: = id_user, 1, 1)) (select @ Rn: = 0, @i: = NULL) vars where number_of_pushups> date = date by ID_USER, TD); TD by TD Group;

Your app can still check against the minimum price.

Note: It assumes that there is only one record per day if you are looking for amount of the number of pushups each day, the above can be easily modified.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -