我尝试使用 proposed query在 Sybase ASE 12 上,它提示语法错误。
SELECT
item,
( SELECT TOP 1 tags.tag
FROM #tags tags
LEFT JOIN t o
ON tags.tag = o.tag
AND o.item_id = n.item_id
WHERE o.tag IS NULL
ORDER BY tags.tag
) 'tag',
value
FROM
t_new n
错误:
Incorrect syntax near the keyword 'top'.
但是,当我用 MAX() 替换 (
TOP 1 tag
... ORDER BY tag
) 时,同样的查询有效:SELECT
item,
( SELECT max(tags.tag)
FROM #tags tags
LEFT JOIN t o
ON tags.tag = o.tag
AND o.item_id = n.item_id
WHERE o.tag IS NULL
-- ORDER BY tags.tag
) 'tag',
value
FROM
t_new n
TOP 1 tag
... ORDER BY tag
) 是个问题? 最佳答案
Adaptive Server Enterprise version 12.5.3 supports the top n clause in outer query select statements, but not in the select list of a subquery. This differs from Microsoft SQL Server. Any attempt to use the top n clause with Adaptive Server in a subquery yields a syntax error.
来自 ASE 12.5.3 文档 here
关于sql - 可以在 Sybase ASE 中使用具有 "TOP 1 column"的相关子查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14860728/