[英]Oracle equivalent of a SQL Server query
I need to know the Oracle equivalent of my SQL Sever query. 我需要知道等同于SQL Sever查询的Oracle。 Could someone please help me? 有人可以帮我吗?
select recno = (select top 1 ld.recno from load ld where ld.crecno = i.recno)
from inputtable i
Check Below Query 检查以下查询
select (select ld.recno from load ld where ld.crecno = i.recno AND RowNum =1)
AS recno from inputtable i
The SUBQUERY
you wrote is not necessary. 该SUBQUERY
你写的是没有必要的。 A INNER JOIN
operation between the LOAD
and INPUTTABLE
tables is a quick way to get the set you are looking for. 在LOAD
和INPUTTABLE
表之间进行INNER JOIN
操作是获取所需集合的快速方法。
SQL Syntax Interpretation: Of all the records in
LOAD
, how many of the ones with valuesCRECNO
have matching values in the columnRECNO
of tableINPUTTABLE
? SQL语法解释:在LOAD
所有记录中,有多少个值为CRECNO
的记录在表INPUTTABLE
RECNO
列中具有匹配的值? Taking those results, what is the FIRST value (TOP(1)) in the output if the results are sorted by...(?)... 取得这些结果,如果结果按...(?)...排序,则输出中的FIRST值(TOP(1))是多少?
There isn't any SORT
priority designated in the OP. OP中未指定任何SORT
优先级。
In a SELECT statement, always use an ORDER BY clause with the TOP clause. 在SELECT语句中,始终将ORDER BY子句与TOP子句一起使用。 This is the only way to predictably indicate which rows are affected by TOP. 这是可预测地指示哪些行受TOP影响的唯一方法。 Reference From: Microsoft Technet . 参考来源:Microsoft Technet 。
To illustrate a correctly formatted SQL statement with repeatable results, I went ahead and rewrote the OP's SQL query assuming that the TOP(n)
solution wanted the first value in an ASCENDING SORT of the RECNO
column values. 为了说明具有正确结果的正确格式的SQL语句,我继续写了OP的SQL查询,并假设TOP(n)
解决方案想要RECNO
列值的升序排序中的第一个值。
Database servers do have a default sorting and selection behavior if important expressions such as an ORDER BY
statement are missing, it is risky however to assume that all defaults are set the same in any given environment. 如果缺少重要的表达式(例如ORDER BY
语句),则数据库服务器确实具有默认的排序和选择行为,但是冒充风险是假定在任何给定环境中所有默认值都设置为相同。
The Rewritten SQL: 重写的SQL:
WITH sub_query AS (
SELECT i.recno
FROM inputtable i, load ld
WHERE i.recno = ld.crecno
ORDER BY i.recno ASC
)
SELECT s.recno
FROM sub_query s
WHERE rownum = 1
The
ROWNUM
evaluation and theORDER BY
criteria can be changed to obtain theTOP(n)
behavior intended. 可以更改ROWNUM
评估和ORDER BY
标准以获得预期的TOP(n)
行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.