Answer the question
In order to leave comments, you need to log in
How to make a selection of users for the period from the date of registration?
Task Display a list of all users who have made more than 30 transactions in USD (WalletSections.Currency = 1) during the year since their registration (Users.RegistrationDate).
How to make a selection for a period of time from Users.RegistrationDate to (Users.RegistrationDate + 1 year)?
Answer the question
In order to leave comments, you need to log in
SELECT Users.UserID
FROM Users
INNER JOIN Wallets ON Users.UserID = Wallets.UserID
INNER JOIN WalletSections ON Wallets.WalletID = WalletSections.WalletID
INNER JOIN Transactions ON WalletSections.WalletSectionID = Transactions.WalletSectionID
WHERE (WalletSections.Currency = 1)
AND (Transactions.CreationDate BETWEEN Users.RegistrationDate AND DATEADD(yy, 1, Users.RegistrationDate))
GROUP BY Users.UserID
HAVING (COUNT(*) > 30)
Oracle:
Select
U.userid, Count (t.transactionid)
From users u, wallets w, walletsections ws, transactions t
Where
u.userid=w.userid and
w.walletid=ws.walletid and
ws.walletsectionid=t.walletsectionid and
to_date(t.creationdate,'dd.mm.yyyy') between to_date(u.registrationdate,'dd.mm.yyyy') and add_month(to_date(u.registrationdate,'dd.mm.yyyy'),12)- 1 and
ws.currency='USD' /*here see for yourself how your currency is encoded*/
group by u.userid
having count(t.transactionid)>30
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question