日期:2014-05-17  浏览次数:20892 次

只有这么多分了 求救
我有2张表,
表A   account
pol_id(保单ID)(不唯一   为每笔缴费都写一行)   amount(金额)   time(缴费时间)(该字段是字符型)   cust_id(用户ID)
表B   CUSTOMER
cust_id   cust_name   cust_cardid(身份证号)

给出一个时间点   比如说   6月20日
我现在要找以下几个条件

同一客户同一天有三笔缴费记录(对于不同保单,同一保单几次缴费只算一次)
同一客户对于三个自然日,每个自然日至少有一笔缴费记录;
同一客户在之前14   个自然日里面   缴费累计超过20W  

只要满足其中任意一个条件,就返回该客户的身份证号码   请问一下怎么写?
大家救急,只有一个礼拜时间   还有很多没写。

------解决方案--------------------
select a.cust_id, count(distinct a.pol_id) from a
where a.time= '6月20日 '
group by a.cust_id
having count(distinct a.pol_id)> =3
union
select a.cust_id, count(distinct trunc(t.time))
where a.time <= '6月20日 ' and a.time> '6月17日 '
group by a.cust_id
having count(distinct trunc(t.time))=3
union
select a.cust_id, sum(a.amount)
where a.time <= '6月20日 ' and a.time> '6月6日 '
group by a.cust_id
having sum(a.amount)> 200000

日期处理就不帮你写了,你自己确定下,关键是在count(distinct)上。



------解决方案--------------------
看看oracle的统计函数over的用法,你这个问题可以使用它来解决