how to select max of mixed string/int column?

后端 未结 6 1253
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 22:10

Lets say that I have a table which contains a column for invoice number, the data type is VARCHAR with mixed string/int values like:

invoice_number
*********         


        
6条回答
  •  孤城傲影
    2020-12-08 22:35

    Your problem is more one of definition & design.

    Select the invoice number with highest ID or DATE, or -- if those really don't correlate with "highest invoice number" -- define an additional column, which does correlate with invoice-number and is simple enough for the poor database to understand.

    select INVOICE_NUMBER 
    from INVOICE_HEADER
    order by ID desc limit 1;
    

    It's not that the database isn't smart enough.. it's that you're asking it the wrong question.

提交回复
热议问题