Can I use group by in a subquery?
I want to do the following:
select count(t) from Ticket t where t.id in (select st.id from Ticket st group by st.owner)
Unfortunately, I g开发者_Go百科et a SQLGrammarException when doing this.
Any ideas?
select st.id from Ticket st group by st.owner
isn't a valid query, so it's not going to be a valid subquery.
If I follow what you're trying to do, try changing the query to this:
select count(t) from Ticket t where t.id in (select st.id from Ticket st group by st.owner, st.id)
What database are you querying? My familiarity is with SQL Server and in that case, yes, the group by in above subquery should work.
精彩评论