Skip to content

Commit

Permalink
Added new report for date of last session for subs
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonbrett committed Feb 15, 2024
1 parent 00c2092 commit c4f8ed8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/Reports.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ WHERE Id NOT IN (SELECT BuyerUserId from BuySells WHERE BuyerUserId IS NOT NULL)
AND Id NOT IN (SELECT DISTINCT UserId from Regulars)
AND Active = 1
ORDER BY FirstName

/* Subs last bought by date */
SELECT Name, SessionDate, BuySellsSessionId, BuyerUserId FROM BuySellsByBuyer
WHERE SellerUserId IS NOT NULL
AND SessionDate = (
SELECT MAX(SessionDate) FROM BuySellsByBuyer bb
WHERE bb.BuyerUserId = BuySellsByBuyer.BuyerUserId
AND bb.SellerUserId IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM BuySellsByBuyer bb2
WHERE bb2.SessionId = bb.SessionId
AND bb2.SellerUserId = bb.BuyerUserId
)
AND NOT EXISTS (
SELECT UserId from Regulars WHERE UserId = bb.BuyerUserId
)
)
ORDER BY SessionDate DESC

0 comments on commit c4f8ed8

Please sign in to comment.