Hql max以及cast简单示例

    技术2025-10-15  13

    hql max基本语法如下:

    String hql = "select max(p.id) from Player p";

    Integer maxId = (Integer) playerDao.getSession().createQuery(hql).uniqueResult();

     

    将某一字段转换为数字型再进行比较处理语法如下:

    String hql = "select max(CAST(p.globalId as integer)) from Player p";Integer maxId = (Integer) playerDao.getSession().createQuery(hql).uniqueResult();

     

    获取某一字符字段除了第一位数转换后比较处理如下:

    String hql = "select max(CAST(SUBSTRING(p.globalId, 2) as integer)) from Player p";Integer maxId = (Integer) playerDao.getSession().createQuery(hql).uniqueResult();

     

     

     

     

     

    最新回复(0)