2
Greetings to all of the forum!
Like everyone who starts learning Mysql, we come across relatively simple problems but we can’t solve.
I created the INFO_PACOTES table that stores information of packages that traffic in my network. The files are processed via shell and stored only the source MAC and the 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 MAC’s.
I created the KNOWN table that is described below. The only thing I need is to add the values of the column size_frame of the INFO_PACOTES table grouped by different "mac_origin" and the result of the sums update the total trafego_field of the KNOWN table.
|Field |Type |Null|Key|Default|Extra|
|mac |char(17) |NO |PRI|NULL | |
|trafego_total|decimal(20,0)|YES | |NULL | |
I 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!
see if my answer helps you
– Rovann Linhalis
@Caiomoreti, I have shown an alternative way to do this query, including the explanation of why it did not work.
– Jefferson Quesado