i'm working on a fictional payment database, and i want to check if there are payments from a merchant which sum of it goes above 10k within 72 hours from each other.
SELECT o.MerchantID, SUM(Amount) FROM Payments p
INNER JOIN Orders o ON p.OrderID = o.ID
WHERE MerchantCreatedOrderOn BETWEEN MerchantCreatedOrderOn AND DATEADD(HOUR, 72, MerchantCreatedOrderOn)
GROUP BY o.MerchantID, o.MerchantCreatedOrderOn, p.ID
HAVING SUM(o.Amount) >= 10000;
now my where clause isn't right yet, i now get only payments where the sum is above 10k but not when it's in 72 hours..
my desired result:
all the payments id's from payments which sum > 10,000 in 72 hours.
this is on SQL-server 14.0.100
i only need the payment id's from those who exceed 10k in 72 hours
so:
|ID |
|427683|
|427685|
|427688|
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…