我有两个表如下:
外壳
+-------+--------------+-----------+-----------+
| name | serialnumber | VCenabled | BCenabled |
+-------+--------------+-----------+-----------+
| ENC01 | 12345 | | |
| ENC02 | 45678 | | |
| ENC03 | 11222 | | |
+-------+--------------+-----------+-----------+
互连
+-------------+-----------+-----------------------+
| description | baynumber | enclosureserialnumber |
+-------------+-----------+-----------------------+
| VC | 1 | 12345 |
| VC | 2 | 12345 |
| BC | 3 | 12345 |
| VC | 1 | 45678 |
| BC | 3 | 45678 |
+-------------+-----------+-----------------------+
我需要更新表中的VCenabled
和BCenabled
列Enclosure
。VCenabled
应该包含表中相应行的计数Interconnect
。同样对于BCenabled
.
这是我需要结束的内容:
+-------+--------------+-----------+-----------+
| name | serialnumber | VCenabled | BCenabled |
+-------+--------------+-----------+-----------+
| ENC01 | 12345 | 2 | 1 |
| ENC02 | 45678 | 1 | 1 |
| ENC03 | 11222 | | |
+-------+--------------+-----------+-----------+
我能够想出这个 SQL 查询,但我没有太多运气将它变成更新。此外,如果我在 Flyspeed Query 中运行此查询,但如果我在 MySQL Workbench 中运行它,我会收到 1064 错误:SQL 语法错误。
Select
enclosure.name,
enclosure.vcenabled,
count(*)
From
enclosure Inner Join
interconnect On interconnect.enclosureserialnumber = enclosure.serialnumber
Where
interconnect.description like '%VC%'
Group By
enclosure.serialnumber
任何帮助,将不胜感激。