select t.id, sum(sale_num) sale_num from t where sale_date between start_date and end_date group by t.id having sum(sale_num) <=10根据具体情况修改吧
start_date 和end_date 你自己算就是了
我也接着优化下: select t.id, sum(t.sale_num) from (select r.id, r.sale_date, min(r.sale_date) over(partition by r.id) as min_date, r.sale_num from web_clm_rule r) t where t.sale_date between t.min_date and t.min_date + 90 group by t.id having sum(t.sale_num) <= 10
from t
where sale_date between start_date and end_date
group by t.id
having sum(sale_num) <=10根据具体情况修改吧
我也接着优化下:
select t.id, sum(t.sale_num)
from (select r.id,
r.sale_date,
min(r.sale_date) over(partition by r.id) as min_date,
r.sale_num
from web_clm_rule r) t
where t.sale_date between t.min_date and t.min_date + 90
group by t.id
having sum(t.sale_num) <= 10