09年前四个月分别是:200901,200902,200903,200904,分别有四个月的用户消费表,bill_200901,bill_200902,bill_200903,bill_200904,表中的均有用户当月的消费d_fee以及用户身份号码subsid,现在想查询这四个月中任意3个月d_fee小于50元的客户清单,怎么实现?

解决方案 »

  1.   

    select id
    from(
    select id from bill_200901 where d_fee<50
    union all
    select id from bill_200902 where d_fee<50
    .
    .
    )
    group by id
    having count(1)>3
      

  2.   

    try
    select subsid from 
    (select subsid from bill_200901 where d_fee<50
    union all
    select subsid from bill_200902 where d_fee<50
    union all
    select subsid from bill_200903 where d_fee<50
    union all
    select subsid from bill_200904 where d_fee<50)
    group by subsid
    having count(*) >3
      

  3.   

    select subsid from 
    (select subsid from bill_200901 where d_fee<50
    union all
    select subsid from bill_200902 where d_fee<50
    union all
    select subsid from bill_200903 where d_fee<50
    union all
    select subsid from bill_200904 where d_fee<50)
    group by subsid
    having count(1) >=3
      

  4.   

    select subsid from 
    (select subsid from bill_200901 where d_fee<50
    union all
    select subsid from bill_200902 where d_fee<50
    union all
    select subsid from bill_200903 where d_fee<50
    union all
    select subsid from bill_200904 where d_fee<50)
    group by subsid
    having count(*) >=3