SQL中的UPDATE列等于其他表中的行数

时间:2018-11-05 02:58:27

标签: mysql sql

我有这个Select,它计算表Local中localName的数量,其中indIP等于表Segment中的indIP并按segmentName

SELECT COUNT(localName) FROM Local L, Segment S WHERE L.indIP = S.indIP  GROUP BY segmentName;

COUNT(localName)

 - 2
 - 1
 - 3

现在我想将此数字放在表Segment的nbRooms列的右行,并显示如下更新:

UPDATE Segment SET nbRooms = *** 

示例:

SELECT * FROM Segment

indIP | segmentName | nbRooms

 - 3---------first ----------------2
 - 4---------second------------1
 - 5---------third----------------3

你能帮我吗?

1 个答案:

答案 0 :(得分:1)

您可以使用相关子查询:

$this->context->controller->registerJavascript(
    'three.js',
    'https://ajax.googleapis.com/ajax/libs/threejs/r84/three.min.js',
    ['position' => 'bottom', 'priority' => 100, 'server' => 'remote']
);