1

Topic: How to show the maximum value taking into account dates?

There is a table with value and date

CREATE TABLE IF NOT EXISTS ` table ` (
` name ` varchar (11) NOT NULL;
` price ` varchar (11) NOT NULL;
` dt ` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO ` table ` (` name `, ` price `, ` dt `) VALUES
(' tampo ', ' 6 ', ' 2017-09-26 3:50:00 PM ');
(' tampo ', ' 7 ', ' 2017-09-26 3:51:00 PM ');
(' tampo ', ' 4 ', ' 2017-09-26 3:52:00 PM ');
(' tampo ', ' 5 ', ' 2017-09-26 3:53:00 PM ');
(' tampo ', ' 1 ', ' 2017-09-26 3:54:00 PM ');

How to show 2 or more lines as reduction of the price but taking into account time.
I turn out I want to receive such output here:
' tampo ', ' 7 ', ' 2017-09-26 3:51:00 PM'
' tampo ', ' 5 ', ' 2017-09-26 3:53:00 PM'
' tampo ', ' 1 ', ' 2017-09-26 3:54:00 PM ' (not mandatory)

2

Re: How to show the maximum value taking into account dates?

ORDER BY

3

Re: How to show the maximum value taking into account dates?

If you mean request of type:

SELECT * FROM table
ORDER BY ` price ` DESC, ` dt ` ASC

That it does not approach, as at first shows sorting according to the price, and then all dates.
It is necessary to me that it showed those dates which more than were

4

Re: How to show the maximum value taking into account dates?

. Why result 7-5-1, instead of 7-4-1, 6-5-1 or 6-4-1?

5

Re: How to show the maximum value taking into account dates?

We sort by the price, we receive 7 6 5 4 1:
+ 7 ceiling price with it also we begin
- 6 does not approach, as date is less than at 7
+ 5 approaches, time is more to that 7
- 4 does not approach, as date is less than at 5
+ 1 approaches, time is more than at 5

6

Re: How to show the maximum value taking into account dates?

... Here LEAD/LAG are not implemented. An optimum  -  and the cursor in it.

7

Re: How to show the maximum value taking into account dates?

Akina wrote:

Uuu... Here LEAD/LAG are not implemented. An optimum  -  and the cursor in it.

...Well "sql variables" give a lead/log, but agree,
To the beginner it is better on stored-procedure....