SELECT * from tt a where exists(select 1 from tt where a.goods_id=goods_id and  attribute=0) and a.attribute=1
or
 not exists(select 1 from tt where a.goods_id=goods_id and  attribute=1) and a.attribute=0