How to group DB values? [closed]

1

I am rephrasing this question more clearly. I have the following challenge; I have a BD that contains 16 fields of information, this BD keeps bets placed on a system, to later be able to process the result and payment of the customer's ticket. In the administration part, the ADM has an area where it is possible to place the results of the games that were made by the client, when the client places a bet, the team name, the type of bet, and the confrontation are stored. For example, there is a game of Vasco and Flamengo, you bet that Vasco will make 2 goals in the second half, in the BD I store this information as follows:

Team name: Vasco.

Type of bet: +2.

Confronto: Vasco x Flamengo.

In the administrative part, ADM has to check all the games that are in the DB, but several clients make the same type of bet, that is, I will have in the DB 15.20 records repeated, with the same < in , even Type of bet and even Confronto .

The administrator, makes the games conference, for a select , I print all the DB records in one, the select has 3 options, won, lost, canceled ". and the record ID of that match, I can update the result in the DB.

But the problem is that it has many repeated results, and it is complicated for the administrator to put the same result in several identical games, for example:

What I want, is to group these games, based on the same confrontation, Condition bet and Bet, and the result that the administrator put in the select, value for all of the same group, without having to put the same result several times . In PHP I can group in sql :

$conexao->prepare('SELECT time_apostado,tipojogo,tipoaposta,codigo  FROM bilhetes_temp WHERE codigo GROUP BY time_apostado,tipojogo,tipoaposta');

But I do not have the slightest idea how to show only 1 result for admin, and make the the result of the select that it put, value for all others that are equal.

I hope I have not been long in explaining, I could not summarize such a question. So, does anyone give me an idea of how I group these results in PHP or also JasvaScript ?

    
asked by anonymous 29.06.2015 / 06:26

1 answer

3

You say in the question that you know the GROUP BY function and that you know to group by a value. You can use this function to group by three columns, thus removing duplicate results.

This can be done as follows:

SELECT Time, TipoDeJogo, DataDoJogo
FROM TABELA_JOGOS
GROUP BY Time, TipoDeJogo, DataDoJogo
ORDER BY Time, TipoDeJogo, DataDoJogo
    
29.06.2015 / 08:06