I have 2 tables User and Role, RoleId is a foreign key in User table,
so I wrote a method here but it is not returning the output I want. I want to count both how many User for example have RoleId = 1 and how many have RoleId = 2:
public int countPersonelAdminandWorker() throws PerdoruesiException {
Query query = em.createNativeQuery("SELECT COUNT(RoleID) FROM User p WHERE p.roleID = 1 ");
try {
return query.getSingleResut();
}
catch(NoResultException e) {
throw new PerdoruesiException("...");
}
}
group by