Solution for calculating deadlines:
Create a new column in the product table, for example, last_used_on . Its data type should be TIMESTAMP (MySQL representation for Unix time).
<strong> Benefits:
- Timestamps contain both date and time.
- This allows VERY accurate calculations and comparisons in relation to dates and times.
- It allows you to format the stored values ββin the date and time format of your choice.
- You can convert from any date format to a timestamp.
- As for your autocomplete fields, this allows you to filter the list of products as you wish. For example, to display all products used with [date-time]. Or get all products used between [date-time-1] and [date-time-2]. Or get products used only on Mondays, at 13:37:12, for the last two years, two months and three days (so flexible timestamps).
Resources
Solution for calculating the speed of use:
Well, in fact, you are not talking about calculating the frequency , but about the rate - although it can be argued that the frequency is also the norm.
Frequency means using time as a reference unit and measuring it in hertz (Hz = [1 / second]). For example, let's say you want to query how many times a product has been used in the past year.
Speed , on the other hand, is a comparison, the relationship between two related units. For example, the USD / EUR exchange rate is both currencies. If a comparison occurs between two members of the same type, the result is a number without units: percentage. For example: 50 apples / 273 apples = 0.1832 = 18.32%
However, I suppose you tried to calculate the utilization rate : the number of uses of the product depending on the number of uses of all products. For example, for a product: usage rate of the product = 17 usages of the product / 112 total usages = 0.1517... = 15.17% . And in autocomplete, you want to display products with a usage speed exceeding a specified percentage (for example, 9%).
It is easy to implement. In the products table, add a usages column of type int or bigint and simply increase its value each time a product is used. And then, when you want to extract the most used products, just apply a filter, as in this sql statement:
SELECT id, name, (usages*100) / (SELECT sum(usages) as total_usages FROM products) as usage_rate FROM products GROUP BY id HAVING usage_rate > 9 ORDER BY usage_rate DESC;
Here is a small study example:

In the end, recyne , frequency and speed are three different things.
Good luck.