我的数据库里面的数据是这样的: 
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语句应该怎么写?谢了!

解决方案 »

  1.   

    select v_name,v_money,v_list,v_flag from table
    where v_name='孙辉' and v_flag=0
      

  2.   


    select * from table where v_name='孙辉' and v_money=3000 and v_flag=0
      

  3.   

    select v_name,v_money,v_list,v_flag from table 
    where v_name='孙辉' and v_money=3000 and v_flag=0
      

  4.   

    select t.* from test t,
    (select v_name from test group by v_name having sum(v_flag)=0) t1
    where t.v_name = t1.v_name
      

  5.   

    select t.* from test t,
    (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
      

  6.   

    select t.* from test t,
    (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那就这样
      

  7.   

    select * from test aa where not exists(select 1 from test bb where  aa.v_name=bb.v_name and aa.v_money=bb.v_money and v_flag=0) and aa.v_name='孙辉' and  v_money=3000
      

  8.   

    还是月亮厉害,v_name是未知的情况。