hql Order By将字符串类型的数字按Interger/Double类型排序

由于当初设计不合理,将type类型设置为varchar了,导致排序成了1、10、2......但期望是按数字类型1、2、10排序的

解决方案一:

改数据库字段类型

解决方案二:


order by t.type
改为(注:integer要小写)

order by cast(t.type as integer)

使用double的时候,如果使用上面的方法则会报错:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'double precision)

改为

order by  CONVERT(t.type,DECIMAL)


order by (t.type+0)



你可能感兴趣的:(ssh,Hibernate,HQL)