现在我根据Table的type字段分组统计数量,type是一个对象
我用的是MySql数据库
用纯SQL语句查询
select typeId, count(*) from Table group by typeId
结果
null : 5
1 : 5
2 : 2
3 : 3
4 : 4
5 : 2用HQL语句查询
select t.type, count(t) from Table t group by t.type
结果
1 : 5
2 : 2
3 : 3
4 : 4
5 : 2
没有了null值的统计,是什么原因啊,应该怎么解决

解决方案 »

  1.   

    没人答,自己来答
    select t.type, count(t) from Table t group by t.type
    改成
    select t.type, count(t.id) from Table t group by t.type
    估计是直接count(t)的话不知道统计t的哪个字段
    而t.id是外键,关联了typeId这个字段,所以null值可以统计了
      

  2.   

    1.count(1)与count(*)得到的结果一致,包含null值。
          2.count(字段)不计算null值
          3.count(null)结果恒为0