Query in HQL using Hibernate

Asked

Viewed 208 times

0

How to do a query to return the result below in HQL

Upshot

| quantidade | quantidade erro |   desc   |

|     2      |         1       |  TESTE 1 |
|     3      |         2       |  TESTE 2 |
|     1      |         1       |  TESTE 3 |

Table

| DESC    |  ERRO |

| TESTE 1 |   0   |
| TESTE 1 |   1   |
| TESTE 2 |   1   |
| TESTE 2 |   0   |
| TESTE 2 |   1   |
| TESTE 3 |   1   |
  • I honestly don’t understand the logic of the consultation. You could better explain the purpose of the query and/or you have an SQL that generates this query, so we can guide us in the construction of HQL/JPQL?

1 answer

1

You need to group the data by Description and count (count) for the grouped quantity, then one SUM to count the number of errors - ERRO, and at the end add the description:

SELECT COUNT(*) as quantidade, SUM(ERRO) as quantidadeErro, desc
FROM tabela
GROUP BY DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.