开发者

Can I use group by in a subquery?

开发者 https://www.devze.com 2023-02-19 07:59 出处:网络
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)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消