title: How to run a select clause with JPQL constructor expression?
body: <p>I have a query to get a count and names and it's like this and when I run this code, it works perfectly, I'm getting the results. </p>
  
  <pre><code>entityManager.createQuery("SELECT d.departmentName,COUNT(a.status) FROM TableA a,TableD d WHERE a.status = 6 and a.waitDepartmentId=d.id group by d.departmentName").getResultList();
  </code></pre>
  
  <p>But, because of the performance issues and some of other issues I have to run the above query with constructor expression in JPA but before running query the IDE warns me that SQL grammer is invalid. The message that shown at comma after d.departmentName is "operator or FROM expected but got ','" The code that I tried is like this:</p>
  
  <pre><code>entityManager.createQuery("SELECT new tr.package.Pojo((SELECT d.departmentName,COUNT(a.status) FROM TableA a,TableD d WHERE a.status = 6 and a.waitDepartmentId=d.id group by d.departmentName)) FROM TableA a").getResultList();
  </code></pre>
  
  <p>How can I run a select query and get some datas with constructor expression in JPA? How can I write correct SQL for second?</p>