-- 优化前语句--普通语句
SELECT
squarefilmrecmd.squareTypeId,
squaretypedata.squareTypeName,
squarefilmrecmd.filmId
FROM
squarefilmrecmd
INNER JOIN squaretypedata ON squarefilmrecmd.squareTypeId = squaretypedata.squareTypeId
AND squarefilmrecmd.filmId = '02fedb31-f44c-44a9-b8ed-035a689715df'
-- 优化后01---------
SELECT
t.squareTypeId,
squaretypedata.squareTypeName,
t.filmId
FROM
(SELECT squareTypeId,
filmId from squarefilmrecmd where squarefilmrecmd.filmId = '02fedb31-f44c-44a9-b8ed-035a689715df') as t
INNER JOIN squaretypedata ON t.squareTypeId = squaretypedata.squareTypeId
-- 优化后02---
SELECT
squareTypeId,
filmId,
(
SELECT
squareTypeName
FROM
squaretypedata
WHERE
squaretypedata.squareTypeId = squarefilmrecmd.squareTypeId
) AS squareTypeName
FROM
squarefilmrecmd
WHERE
filmId = '02fedb31-f44c-44a9-b8ed-035a689715df'
SELECT
squarefilmrecmd.squareTypeId,
squaretypedata.squareTypeName,
squarefilmrecmd.filmId
FROM
squarefilmrecmd
INNER JOIN squaretypedata ON squarefilmrecmd.squareTypeId = squaretypedata.squareTypeId
AND squarefilmrecmd.filmId = '02fedb31-f44c-44a9-b8ed-035a689715df'
-- 优化后01---------
SELECT
t.squareTypeId,
squaretypedata.squareTypeName,
t.filmId
FROM
(SELECT squareTypeId,
filmId from squarefilmrecmd where squarefilmrecmd.filmId = '02fedb31-f44c-44a9-b8ed-035a689715df') as t
INNER JOIN squaretypedata ON t.squareTypeId = squaretypedata.squareTypeId
-- 优化后02---
SELECT
squareTypeId,
filmId,
(
SELECT
squareTypeName
FROM
squaretypedata
WHERE
squaretypedata.squareTypeId = squarefilmrecmd.squareTypeId
) AS squareTypeName
FROM
squarefilmrecmd
WHERE
filmId = '02fedb31-f44c-44a9-b8ed-035a689715df'