Greetings to all of the forum!
As everyone who starts learning MySQL, we come across relatively simple problems that we can not solve.
I created the INFO_PACOTES table that stores packet information that travels on my network. The files are processed via the shell and stored only the source MAC and package size.
mysql> desc INFO_PACOTES;
| Field | Type |Null | Key |Default | Extra |
|mac_origem |char(17) |YES | | NULL | |
|tamanho_frame|decimal(5,0)|YES | | NULL | |
As a normal network, several devices are connected and monitored. Thus, there will be several devices with different MACs.
I created the KNOWN table that is described below. The only thing I need is to add the values of the column_frame column of the INFO_PACOTES table grouped by different "mac_origem" and the result of the sums update the field total_traffic of the table NAME.
|Field |Type |Null|Key|Default|Extra|
|mac |char(17) |NO |PRI|NULL | |
|trafego_total|decimal(20,0)|YES | |NULL | |
I have created the following sentence below:
UPDATE CONHECIDOS, INFO_PACOTES
SET trafego_total = (SELECT sum(tamanho_frame) FROM INFO_PACOTES
GROUP BY INFO_PACOTES.mac_origem)
WHERE CONHECIDOS.mac=INFO_PACOTES.mac_origem;
At the end of the sentence, select results in more than one line, generating the error:
ERROR 1242 (21000) : Subquery returns more than 1 row
Can anyone tell me what I'm missing?
Thank you!