JPQL cross tab query
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-05-10T14:19:32Z
Indexed on
2010/05/10
19:04 UTC
Read the original article
Hit count: 647
Hi can anyone tell me if its possible to write a cross tab query in JPQL?
(I'm using eclipse link JPA2)
An example of a cross tab query in SQL can found here http://onlamp.com/pub/a/onlamp/2003/12/04/crosstabs.html
SELECT dept, COUNT(CASE WHEN gender = 'm' THEN id ELSE NULL END) AS m, COUNT(CASE WHEN gender = 'f' THEN id ELSE NULL END) AS f, COUNT(*) AS total FROM person GROUP BY dept
How can I do the same thing as a single query in JPQL?
Looking at the spec it doesn't seem to look like CASE is valid in COUNT
Is there any other way?
© Stack Overflow or respective owner