Select max int from varchar column

前端 未结 9 1242
离开以前
离开以前 2021-02-19 04:07

I am trying to retrieve the largest number from a varchar column that includes both numbers and strings. An example of the data I\'m working with:

BoxNumber

9条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 04:57

    SELECT MAX(CAST(value as signed)) FROM yourTable
    WHERE VALUE NOT LIKE '%[a-z]%'
    AND ISNUMERIC(VALUE) = 1
    

    In MySql

    You should use signed instead of int to cast correctly.

    P.s types used to cast may differ in MySql

    For more conversions visit this link

提交回复
热议问题