I have in my DB a column of varchar type.
Table name: Transcations
Column name :authprocess
I want to find min() value on the varchar column.
authprocess
A1D1
A1D3
A1D4
A1D1
A1B1
A1D5
......
i am using the command
select min(authpr开发者_Go百科ocess) from Trnascation then it give the "0000" valuePlease tell me the command in Mysql.
MIN() makes no real sense for a character string, your best bet is to do a string sort by ascending values and select the top one perhaps??
SELECT TOP 1 FROM table ORDER ASC;
MIN()
takes the first entry after sorting. For text columns, the sorting order is ascii order, so for alpha-numeric data it's 0..9a..zA..Z
You must have an entry with the value 0000
, which will of course be the minimum.
It sounds like you need to restrict your search to "valid" entries. Assuming entries are valid if they have form letter-digit-letter-digit, try this:
select min(authprocess)
from Transcations
where authprocess regexp '[A-Z]\d[A-Z]\d'
You can adjust the regex to suit whatever your needs are - eg perhaps it's A-digit-D-digit
, which would match the regex 'A\dD\d'
精彩评论