K
K
Kirill Petrov2018-08-20 11:47:47
MySQL
Kirill Petrov, 2018-08-20 11:47:47

How to create a query to get a value from a date range, taking into account the amount of time in the requested period relative to the data in the table?

Greetings. There is a table in the MySQL database:
5b7a784d1f915211013240.png
How to create a query in which the initial data will be date ranges, and the result will be a value with a proportion relative to the amount of time (days)?
For example, the initial data is 2 ranges:
2018-07-01 - 2018-07-09 and 2018-07-20 - 2018-08-09
As a result, I want to get this:
5b7a7e202eb28642343313.png
I tried to generate an intermediate table with each individual day and value and then collect data through SUM, but this method gives errors for large periods, and there is no way to reduce the segmentation to seconds...
The point is that I have subscriber service customers who pay for a period, the task is to calculate income for certain date ranges.
Thanks in advance for your reply.
I would appreciate links to articles on this topic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-08-20
@BorisKorobkov

First, learn how to spell correctly.
Secondly, if I correctly understood this stream of consciousness, then the task is formulated as "find the intersection of the date range." And see this. https://habr.com/post/209138/
And I hope you can calculate the ratio yourself as an ordinary division.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question