cd 发帖数: 32 | 1 假设表test内容如下,
col_A col_B |
B*****g 发帖数: 34098 | 2 oracle:
SELECT (SELECT col_b
FROM test
WHERE col_a = 4
AND rownum = 1) col_b
FROM DUAL
sql server
SELECT (SELECT TOP 1 col_b
FROM test
WHERE col_a = 4) col_b
FA BAO ZI !!!!!!!!!!!!!!!!!!!!!!
【在 cd 的大作中提到】 : 假设表test内容如下, : col_A col_B
|
d*h 发帖数: 2347 | 3 Thought you can do it, this is still a very stupid requirement, in relative
database, row sequence is not relevant.
【在 cd 的大作中提到】 : 假设表test内容如下, : col_A col_B
|
n********6 发帖数: 1511 | 4 我以前遇到过类似的问题,不敢用select top。高人指点一下select top如何产生?
msdn说top在order by时按顺序产生.高人解释一下。
If the query includes an ORDER BY clause, the first expression rows, or expression percent of rows, ordered by the ORDER BY clause are returned. If the query has no ORDER BY clause, the order of the rows is arbitrary.
MSDN说top在insert, update时是随机的。
The rows referenced in the TOP expression used with INSERT, UPDATE, MERGE,
or DELETE are not arranged in any order. TOP n returns n random rows.
http://msdn.microsoft.com/e
【在 B*****g 的大作中提到】 : oracle: : SELECT (SELECT col_b : FROM test : WHERE col_a = 4 : AND rownum = 1) col_b : FROM DUAL : sql server : SELECT (SELECT TOP 1 col_b : FROM test : WHERE col_a = 4) col_b
|
B*****g 发帖数: 34098 | 5 we have this kind of requirement many times in oracle.
relative
【在 d*h 的大作中提到】 : Thought you can do it, this is still a very stupid requirement, in relative : database, row sequence is not relevant.
|
cd 发帖数: 32 | 6 谢谢beijing, 是oracle。
但是你的query在col_a里面没有4出现的时候没有返回值。
【在 B*****g 的大作中提到】 : oracle: : SELECT (SELECT col_b : FROM test : WHERE col_a = 4 : AND rownum = 1) col_b : FROM DUAL : sql server : SELECT (SELECT TOP 1 col_b : FROM test : WHERE col_a = 4) col_b
|
B*****g 发帖数: 34098 | 7 it has, the value is NULL.
SELECT NVL((SELECT col_b
FROM test
WHERE col_a = 4
AND rownum = 1), 'fail') col_b
FROM DUAL
【在 cd 的大作中提到】 : 谢谢beijing, 是oracle。 : 但是你的query在col_a里面没有4出现的时候没有返回值。
|
cd 发帖数: 32 | 8 Yes you are right. The requirment actually is asking to return any col_b
just for one row if there is any . Maybe I didn't say it clearly. thank you!
relative
【在 d*h 的大作中提到】 : Thought you can do it, this is still a very stupid requirement, in relative : database, row sequence is not relevant.
|
cd 发帖数: 32 | 9 nice!
好,马上奉上包子 请稍等。。。。
【在 B*****g 的大作中提到】 : it has, the value is NULL. : SELECT NVL((SELECT col_b : FROM test : WHERE col_a = 4 : AND rownum = 1), 'fail') col_b : FROM DUAL
|
B*****g 发帖数: 34098 | 10 赫赫,还是大包子
【在 cd 的大作中提到】 : nice! : 好,马上奉上包子 请稍等。。。。
|
|
|
cd 发帖数: 32 | 11 不知道行情,不嫌少就成 赫赫
【在 B*****g 的大作中提到】 : 赫赫,还是大包子
|
b*****e 发帖数: 364 | 12 Beijing is always hungry. ;-)
【在 B*****g 的大作中提到】 : 赫赫,还是大包子
|
c*******e 发帖数: 8624 | 13 does this work for you?
【在 cd 的大作中提到】 : nice! : 好,马上奉上包子 请稍等。。。。
|
B*****g 发帖数: 34098 | 14 不work他能发包子吗
【在 c*******e 的大作中提到】 : does this work for you?
|
B*****g 发帖数: 34098 | |
c*******e 发帖数: 8624 | |
B*****g 发帖数: 34098 | 17 kick。05才开始学db
接触
个女
【在 c*******e 的大作中提到】 : 你没有看错,就是她,哈哈哈
|
h****n 发帖数: 101 | 18
expression percent of rows, ordered by the ORDER BY clause are returned. If
the query has no ORDER BY clause, the order of the rows is arbitrary.
你觉得insert/update的时候顺序重要吗?order by的时候呢?
【在 n********6 的大作中提到】 : 我以前遇到过类似的问题,不敢用select top。高人指点一下select top如何产生? : msdn说top在order by时按顺序产生.高人解释一下。 : If the query includes an ORDER BY clause, the first expression rows, or expression percent of rows, ordered by the ORDER BY clause are returned. If the query has no ORDER BY clause, the order of the rows is arbitrary. : MSDN说top在insert, update时是随机的。 : The rows referenced in the TOP expression used with INSERT, UPDATE, MERGE, : or DELETE are not arranged in any order. TOP n returns n random rows. : http://msdn.microsoft.com/e
|