A
A
AstralProjection2019-11-26 01:35:58
SQL
AstralProjection, 2019-11-26 01:35:58

How to make a selection of users for the period from the date of registration?

5ddc51c45e4b4058317809.jpeg
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

2 answer(s)
K
Konstantin Tsvetkov, 2019-11-26
@AstralProjection

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)

A
Allezhik, 2019-11-26
@Allezhik

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 question

Ask a Question

731 491 924 answers to any question