8
I have the table Upshot with thousands of data, Table Result
NOME_CASA, NOME_OPONENTE, RESULTADO_FINAL, NOTA_FINAL.
timeAzul timePreto 1 2
timeAzul timeBranco 2 2.10
timeBranco timeAzul 3 2.20
timeCinza timeAzul 3 1.7
timeverde timePreto 1 1.92
timePreto timeRosa 2 2.05
timeAzul timeBranco 1 2.08
Above I showed only a summary of the columns and data in the table, observe that the data can be repeated, for better understanding of the question divided into 2 query that will help us in my doubt:
QUERY 1- Return all the team of the house, that the final note is between 2 and 2.20.
SELECT NOME_CASA FROM Resultado where NOTA_FINAL between 2 and 2.20
QUERY 2 - Return all home team, with final score between 2 and 2.20, and filter the final result equal to 1.
SELECT NOME_CASA FROM Resultado where NOTA_FINAL between 2 and 2.20 and RESULTADO_FINAL = 1 ;
Look what I did in the whole table. Now, I need to get all NOME_CASA that apply the two filters I mentioned for each specific team, ie return the names of the teams where playing with nota_final 2 and 2.20, 60% of the time or more end with the result_final =1; In other words, I would test this condition for each team, and return their name.
Summarizing I need the names of the teams(NOME_CASA
) without duplicating, that 60% of the times end with the resultado_final = 1
, when the NOTA_FINAL
between 2 and 2.20.
Using the data I posted as an example, only the timeAzul would return in the query I need, because in a total of 3 games of timeAzul, 3 met Query1 and 2 of them ended with the result_final = 1. So (2 * 100) / 3 = 66.6%
How to mount this query?
Hello Clara, from what I understand you want to bring teams that have a total of records (using Query2 filters) above 60% of the amount of results from QUERY1, right?
– RXSD
@Andréfilipe actually want to look for all teams (nameCasa) that in 60% or more of the times, had the result_final = 1, when their nota_final is between 2 and 2.20. Note that the Query1 I used is for every table I can have wrong in this, I need to know each team. Example all the blue team played and was the final nota_between 2 and 2.20, let’s say return 10 games, now I need to know how many of these games the result_final = 1, let’s say q was 7, so we have 70%. Since this was for just one team,.
– Clara Campos
@Andréfilipe just edited the post, I may have expressed myself wrong
– Clara Campos
Clara, I made an answer to your case and give me a feedback if it’s as expected.
– RXSD