Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从数据库中获取 2 个不同值的行数。我如何为此编写休眠条件查询?例如,在我的表中包含一个名为“status”的字段,其值为 0 和 1。我怎样才能得到我的表中有多少个 0 和多少个 1?
这会做
select count(status) from table group by status
休眠标准
List result = session.createCriteria(Table.class) .setProjection(Projections.projectionList() .add(Projections.groupProperty("status")) .add(Projections.count("status")) ).list();