Ich habe die folgende Abfrage, die mir die Anzahl der Male eine Person führt eine Transaktion von mindestens $ 1.000 genau zweimal in einem Zeitraum von sieben Tagen zu identifizieren erlaubt:automatisch erneut ausführt eine SQL-Abfrage mit verschiedenen Parametern
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;
Ich möchte die Abfrage erneut ausführen, um zu sehen, wie sich die Ergebnisse ändern, wenn ich die Parameter ändere (mit [$ 1000, $ 2000, $ 3000, $ 4000, $ 5000, $ 6000, $ 7000, $ 8000, $ 9000] als Minimum Summe (currency_amount) Schwelle und [1, 2, 3, 4, 5, 6] als Voraussetzung rolling_visit_sum). Ich kann mir vorstellen, dass dies mit einer Art von Schleife automatisiert werden kann, aber ich bin neu darin und habe mich verwirrt, als ich versuchte, selbst zu suchen, wie ich das machen könnte.
Idealerweise würde ich mit einer Ausgabetabelle so etwas wie das folgende am Ende (mit dem x ‚s mit den Abfrageergebnissen bevölkert:
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
Das tatsächliche Format der Ergebnisse spielt keine große Rolle, solange ich in der Lage bin, die Ergebnisse für jede Kombination von Parametern zu unterscheiden.Eine Anleitung wäre sehr willkommen!