我的数据库里面的数据是这样的:
v_name v_money v_list v_flag
李忠 2000 1 0
李忠 2000 2 0
李忠 2000 3 1
孙辉 3000 1 0
孙辉 3000 2 0
孙辉 3000 3 0
.....
.....
..... 以v_name,v_money为条件,要查询v_flag为全零的数据。上面的数据查询后得到如下结果:
v_name v_money v_list v_flag
孙辉 3000 1 0
孙辉 3000 2 0
孙辉 3000 3 0 不知道这样的SQL语句应该怎么写?谢了!
v_name v_money v_list v_flag
李忠 2000 1 0
李忠 2000 2 0
李忠 2000 3 1
孙辉 3000 1 0
孙辉 3000 2 0
孙辉 3000 3 0
.....
.....
..... 以v_name,v_money为条件,要查询v_flag为全零的数据。上面的数据查询后得到如下结果:
v_name v_money v_list v_flag
孙辉 3000 1 0
孙辉 3000 2 0
孙辉 3000 3 0 不知道这样的SQL语句应该怎么写?谢了!
where v_name='孙辉' and v_flag=0
select * from table where v_name='孙辉' and v_money=3000 and v_flag=0
where v_name='孙辉' and v_money=3000 and v_flag=0
(select v_name from test group by v_name having sum(v_flag)=0) t1
where t.v_name = t1.v_name
(select v_name from test where v_name='孙辉' and v_money=3000 group by v_name having sum(v_flag)=0) t1
where t.v_name = t1.v_name
(select v_name from test group by v_name having sum(case when v_flag=0 then 0 else 1 end)=0) t1
where t.v_name = t1.v_name那就这样