日期:2014-05-16  浏览次数:20860 次

小问题mysql count()函数
select count(a.num) from a
表a的num字段类型是int,值可能是null或数字
可以让上面的sql语句输出的结果,null的时候为0,数字的时候返回最大值。
最好能在hibernate里面也能通用?谢谢

------解决方案--------------------
select max(a.num) from a
------解决方案--------------------
select max(case when a.num is null then 0 else a.num) from a