avatar
B*g
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

avatar
d*h
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

avatar
n*6
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

avatar
B*g
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.

avatar
cd
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

avatar
B*g
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出现的时候没有返回值。

avatar
cd
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.

avatar
cd
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

avatar
B*g
10
赫赫,还是大包子

【在 cd 的大作中提到】
: nice!
: 好,马上奉上包子 请稍等。。。。

avatar
cd
11
不知道行情,不嫌少就成 赫赫

【在 B*****g 的大作中提到】
: 赫赫,还是大包子
avatar
b*e
12
Beijing is always hungry. ;-)

【在 B*****g 的大作中提到】
: 赫赫,还是大包子
avatar
c*e
13
does this work for you?

【在 cd 的大作中提到】
: nice!
: 好,马上奉上包子 请稍等。。。。

avatar
B*g
14
不work他能发包子吗

【在 c*******e 的大作中提到】
: does this work for you?
avatar
B*g
15
千千姐是谁?
avatar
c*e
16
你没有看错,就是她,哈哈哈
avatar
B*g
17
kick。05才开始学db

接触
个女

【在 c*******e 的大作中提到】
: 你没有看错,就是她,哈哈哈
avatar
h*n
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。