sql - Finding records sets with GROUP BY and SUM -


i'd query every groupid (which come in pairs) in both entries have value of 1 hasdata.

|groupid | hasdata | |--------|---------| |  1     |  1      | |  1     |  1      | |  2     |  0      | |  2     |  1      | |  3     |  0      | |  3     |  0      | |  4     |  1      | |  4     |  1      | 

so result be:

1 4 

here's i'm trying, can't seem right. whenever group by on groupid have access in selector

select groupid table group groupid, hasdata having sum(hasdata) = 2  

but following error message because hasdata acutally bit:

operand data type bit invalid sum operator. 

can count of 2 both records true?

just exclude group id's have record hasdata = 0.

select distinct a.groupid table1  not exists(select * table1 b b.hasdata = 0 , b.groupid = a.groupid) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -