使用临时 table 的左连接不起作用
Left join using temporary table is not working
我正在尝试在 table "x" 上执行 "left join" 但我需要 "row_number",所以我正在使用临时 table "with" 命令,但查询不起作用,我收到以下错误:
SQL Error [156] [S1000]: Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Incorrect syntax near ')'.`
有人知道如何解决这个问题
SELECT telefoneEnriquecido1. FROM VPOTPRP P
LEFT JOIN (
WITH tel AS (
SELECT
ID_PROSP,
DT_INC,
ID_NUM_TEL AS novoTelefone,
DT_ATC AS dataAtualizacao,
ROW_NUMBER() OVER (PARTITION BY ID_PROSP ORDER BY DT_ATC DESC) AS rowNumber
FROM
VPOTTEL
)
SELECT
FROM tel
WHERE
rowNumber = 1
) telefoneEnriquecido1 on p.ID_PROSP = telefoneEnriquecido1.ID_PROSP
奇怪的语法。我总是发现嵌入在查询中的 CTE 令人困惑,尽管有些数据库支持它们。我没有发现 CTE 向查询添加任何内容;只需使用子查询:
SELECT . . . -- whatever columns you want
FROM VPOTPRP P LEFT JOIN (
(SELECT ID_PROSP, DT_INC, ID_NUM_TEL AS novoTelefone,
DT_ATC AS dataAtualizacao,
ROW_NUMBER() OVER (PARTITION BY ID_PROSP ORDER BY DT_ATC DESC) AS rowNumber
FROM VPOTTEL
) PL
ON P.ID_PROSP = PL.ID_PROSP AND rowNumber = 1
我正在尝试在 table "x" 上执行 "left join" 但我需要 "row_number",所以我正在使用临时 table "with" 命令,但查询不起作用,我收到以下错误:
SQL Error [156] [S1000]: Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'WITH'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Incorrect syntax near ')'.`
有人知道如何解决这个问题
SELECT telefoneEnriquecido1. FROM VPOTPRP P
LEFT JOIN (
WITH tel AS (
SELECT
ID_PROSP,
DT_INC,
ID_NUM_TEL AS novoTelefone,
DT_ATC AS dataAtualizacao,
ROW_NUMBER() OVER (PARTITION BY ID_PROSP ORDER BY DT_ATC DESC) AS rowNumber
FROM
VPOTTEL
)
SELECT
FROM tel
WHERE
rowNumber = 1
) telefoneEnriquecido1 on p.ID_PROSP = telefoneEnriquecido1.ID_PROSP
奇怪的语法。我总是发现嵌入在查询中的 CTE 令人困惑,尽管有些数据库支持它们。我没有发现 CTE 向查询添加任何内容;只需使用子查询:
SELECT . . . -- whatever columns you want
FROM VPOTPRP P LEFT JOIN (
(SELECT ID_PROSP, DT_INC, ID_NUM_TEL AS novoTelefone,
DT_ATC AS dataAtualizacao,
ROW_NUMBER() OVER (PARTITION BY ID_PROSP ORDER BY DT_ATC DESC) AS rowNumber
FROM VPOTTEL
) PL
ON P.ID_PROSP = PL.ID_PROSP AND rowNumber = 1