MySQL Forums
Forum List  »  Newbie

Re: Group-wise Maximum performance
Posted by: Felix Geerinckx
Date: May 04, 2005 12:54AM

Jon Richards wrote:

> What is the significance of the 20 and 21 in the statement?


In the expression

SUBSTRING(MAX(CONCAT(LPAD(time, 20, '0'), data)), 21)

the 20 and 21 are arbitrary. You need to LPAD your integers with zeroes to make sure they sort correctly. With 20, you make these integers 20 characters long, with leading zeroes where necessary.
Depending on your concrete data, you can pick a more appropriate value.

The 21 (=20+1) is the starting position of your data in the concatenated string, and the SUBSTRING function extracts only the data from the result.

--
felix

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.