0
我有以下查詢,這讓我在7天的時間內識別次數的個別行爲進行不少於$ 1,000的交易正是兩次:自動重新運行具有不同參數的SQL查詢
select count(*)
from (
select id, date, visit_count, daily_total_amount,
sum(visit_count) over (partition by id order by date range between interval '6' day preceding and current row) as rolling_visit_sum
from (
select id, date, count(*) as visit_count, sum(total_amount) as daily_total_amount
from (
select id, date, time, store, sum(currency_amount) as total_amount
from table
group by id, date, time, store
having sum(currency_amount) >= 1000
)
group by id, date
order by id, date
)
group by id, date, visit_count, daily_total_amount
)
where rolling_visit_sum = 2;
我想重新運行查詢,看看結果如何隨着我改變參數(使用[$ 1000,$ 2000,$ 3000,$ 4000,$ 5000,$ 6000,$ 7000,$ 8000,$ 9000]作爲最小sum( currency_amount)閾值和[1,2,3,4,5,6]作爲必要條件rolling_visit_sum)。我想這可以通過某種循環來實現自動化,但是當我嘗試搜索如何自己做這件事時,我對此很陌生並且感到困惑。
理想我想結束與一個輸出表類似於下面的(與X的填充查詢結果:
sum(currency_amount) | rolling_visit_sum | count(*)
1000 1 x
1000 2 x
1000 3 x
1000 4 x
1000 5 x
1000 6 x
2000 1 x
2000 2 x
2000 3 x
2000 4 x
.......
sum(currency_amount) | rolling_visit_sum | count(*)
9000 3 x
9000 4 x
9000 5 x
9000 6 x
只要我能夠區分每個參數組合的結果,結果的實際格式並不重要,任何指導都將非常感謝!