DEV Community

MaxPlatinum
MaxPlatinum

Posted on

Select transactions

(Trying to format query below but its not working)

Hello!

In Oracle DB there is created a view to check Money Transactions (with columns like id, receiver, sender, date, amount etc.) which contains 10 tables connected to each other. So, we have query selecting by quantity of transactions in given time period:

`SELECT *
FROM view_transactions
WHERE TRUNC (datedoc) >= DATE ('01/01/2023', 'dd/mm/yyyy')
AND TRUNC (datedoc) <= DATE ('29/01/2023', 'dd/mm/yyyy')
AND receiver IN
(SELECT receiver
FROM (SELECT COUNT (receiver) counter, receiver
FROM view_transactions
WHERE TRUNC (datedoc) >=
DATE ('01/01/2023', 'dd/mm/yyyy')
AND TRUNC (datedoc) <=
DATE ('29/01/2023', 'dd/mm/yyyy')

                    GROUP BY receiver)
             WHERE counter >= 13)
Enter fullscreen mode Exit fullscreen mode

ORDER BY id`

Here number 13, it says to display the receivers who received money more than 13 times in the period of the month.

And now I have to make this query more diffficult. Also need search for the senders who send more than 3 or more times for that receivers who received money 13 times. If senders meet 3 or more times, so need to group receiver and sum amount.

Example, this months Bill got 15 times money transactions from different senders, and he received from Dell 5 times with amount of 120$, 250$, 312$, 500$ and 50$. John and Michael sent to Bill by 2 times each.
So need to display:

receiver sender sum

  • Bill Dell 1232
  • Bill John some summa
  • Bill Michael some summa

Could anyone help to do this?

Top comments (0)