Sql 我的查询耗时超过30分钟,但不确定是否会显示结果
以下是查询:Sql 我的查询耗时超过30分钟,但不确定是否会显示结果,sql,Sql,以下是查询: SELECT states.name, equipment.type, sum(equipment_events.total), (SUM(equipment_locations.amount) - SUM(equipment_events.total)) FROM States, Locations, Equipment_locations, equipment, equipment_events,
SELECT
states.name,
equipment.type,
sum(equipment_events.total),
(SUM(equipment_locations.amount) - SUM(equipment_events.total))
FROM
States,
Locations,
Equipment_locations,
equipment,
equipment_events,
events
WHERE
equipment.id = equipment_events.equipment_id
and states.id = locations.state_id
and locations.id = events.location_id
and equipment.id = equipment_events.equipment_id
GROUP BY
states.name;
你似乎有一个交叉连接在那里,这可以解释糟糕的表现。每日小贴士:停止使用老式的联接语法编写表联接。相反,请始终使用现代的显式联接。@TimBiegeleisen为什么选择不使用正确的、显式的、标准的、可读的
JOIN
语法?如果您正在学习SQL,那么学习此类查询的正确语法就更为重要。请看一看现代连接语法。这是MSSQL中的语法吗?然后请添加查询执行计划,请参见: