sql - Select where count of other query of same table -



sql - Select where count of other query of same table -

i have got table "members" fields id,userid,groupid , select groupids count of members more 1 each members, this:

id userid groupid 1 1 1 /* selecting groups guy id 1, here 3 people */ 2 2 1 3 3 1 4 1 2 /* here guy lone in group, ignore him! */ 5 1 3 /* select 1 guy 1, because #members>1 */ 6 2 3

performing grouping select guy id 1 including there must atleast 2 people in same group, return: 1, 3

but have no thought how in sql, this, but, doesn't work:

select groupid members userid=1 , count( select userid members groupid=**currently iterated group** )>1;

is somehow possible?

if understand correctly, want groups @ to the lowest degree 2 members, 1 of has userid = 1. next query finds these groups using group by , having:

select m.groupid members m grouping m.groupid having count(*) > 1 , sum(case when m.userid = 1 1 else 0 end) > 0;

sql select count

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -