12
I want to display people’s names (recipient
) who received at least 1024
in a maximum of 3 transactions.
Here the table "transfers":
sender | recipient | date | amount
------------+------------+------------+--------
Smith | Williams | 2000-01-01 | 200
Smith | Taylor | 2002-09-27 | 1024
Smith | Johnson | 2005-06-26 | 512
Williams | Johnson | 2010-12-17 | 100
Williams | Johnson | 2004-03-22 | 10
Brown | Johnson | 2013-03-20 | 500
Johnson | Williams | 2007-06-02 | 400
Johnson | Williams | 2005-06-26 | 400
Johnson | Williams | 2005-06-26 | 200
Answer: Johnson and Taylor.
How to do this query?
How a transaction is defined?
– Ismael
Have how to put the Inserts? need to add value, count (transactions) and believe using a having
– rray
Tip, search by using GROUP BY and HAVING https://www.w3schools.com/sql/sql_having.asp
– Motta
Johnson got over 1024, only in four transactions .... All right? So the only one who fits in there is Taylor
– rray
this is part of a test for a company. I would have to build the query using only sql. Database mysqli.
– zwitterion
Note: mysqli is not database, is API, the database is mysql.
– Guilherme Nascimento
@Guilhermenascimento you are correct. I wrote one thing thinking another.
– zwitterion
I think we can do with a recursive CTE limited to depth 3... Just a few good minutes while I write the query on mobile
– Jefferson Quesado
@rray, 512, 500 and 100. These are Johnson’s transactions
– Jefferson Quesado
@Jeffersonquesado Johnson has four transactions, not three, 512, 100, >>10<<<, 500.
– Inkeliz
@Inkeliz But with three of those four he manages to add up. That’s the question
– Jefferson Quesado