select auth.authorName, count(case when book.category = 1 then 1 else null end) as type1count, count(case when book.category = 2 then 1 else null end) as type2count from package.Book book inner join book.author auth group by auth.authorName
我试了一下用count好像不行,换种写法如下 select new Map( auth.authorName, sum(case when book.category = 1 then 1 else 0 end) as type1count, sum(case when book.category = 2 then 1 else 0 end) as type2count ) from package.Book book inner join book.author auth group by auth.authorName
TO diaopeng(放飞自己): 是么,虽然支持子查询,那我给的那样的SQL语句怎样直接写实现呢?
auth.authorName,
count(case when book.category = 1 then 1 else null end) as type1count,
count(case when book.category = 2 then 1 else null end) as type2count
from
package.Book book
inner join book.author auth
group by
auth.authorName
select
new Map(
auth.authorName,
sum(case when book.category = 1 then 1 else 0 end) as type1count,
sum(case when book.category = 2 then 1 else 0 end) as type2count
)
from
package.Book book
inner join book.author auth
group by
auth.authorName
是么,虽然支持子查询,那我给的那样的SQL语句怎样直接写实现呢?