至少连续5个工作日交易金额大于50000元的记录!
select *
from table a
where 交易日期>=date and 交易日期<=dateadd(d,5,date)
and exists(select 交易日期 from table and 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 group by 交易日期 having count(*)=5)
and exists(select sum(交易金额) from table and 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 group by 客户代码 having sum(交易金额)>=50000)
至少连续5个工作日交易金额大于50000元的记录!(用游标对DTAE赋值)
修改
select *
from table a
where 交易日期>=date and 交易日期<=dateadd(d,5,date)
and exists(select 交易日期 from table where 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 and 交易日期=a.交易日期 group by 交易日期 having count(*)=5) and exists(select sum(交易金额) from table where 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 and 交易日期=a.交易日期 group by 客户代码 having sum(交易金额)>=50000)
同一天交易三次并且交易金额大于10000元(每次)
select *
from table a
where exists(select 客户代码, 交易日期 from table where 客户代码=a.客户代码 and 客户代码=a.客户代码 and 交易日期=a.交易日期 group by 交易日期 having count(*)>=3) and not exists(select * from table where 客户代码=a.客户代码 and 交易日期=a.交易日期 and 交易金额<10000)
同一天交易三次并且交易金额大于10000元(每次)
select *
from table a
where exists(select 客户代码, 交易日期 from table 客户代码=a.客户代码 and 客户代码=a.客户代码 and 交易日期=a.交易日期 group by 交易日期 having count(*)>=3)
and not exists(select * from table 客户代码=a.客户代码 and 交易日期=a.交易日期 and 交易金额<10000)
至少连续5个工作日交易金额大于50000元的记录!
select *
from table a
where 交易日期>=date and 交易日期<=dateadd(d,5,date)
and exists(select 交易日期 from table and 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 group by 交易日期 having count(*)=5)
and exists(select sum(交易金额) from table and 交易日期>=date and 交易日期<dateadd(d,5,date) and 客户代码=a.客户代码 group by 客户代码 having sum(交易金额)>=50000)