北京一家网络公司招聘栏中发布的面试题
-------------------题目Begin----------------------有表T,该表只有一列i,该列i信息(数据)如下:
1
NULL
2
3
8
用SQL语句求如下的结果集(一列):
0
1
2
3
4
要求:使用一条语句得到结果(不得使用子查询)
-------------------End----------------------
这是个SQL题目,经本人多次调试,没找到正解,有哪位大虾帮我解下?不慎感激! --------------------编程问答-------------------- 想要得值是0,1,2,3,8还是,0,1,2,3,4 --------------------编程问答-------------------- select nvl(i,0) As i from tablename order by i
这个就能得到0,1,2,3,8
没有nvl函数用select (case when i is null then 0 else i end) As i from tablename order by i
结果都是0,1,2,3,8 --------------------编程问答-------------------- select isnull(i, 0) as i_sorted from T order by i_sorted asc
--------------------编程问答--------------------
select case when isnull(i,0)>4 then 4 else isnull(i,0) end--------------------编程问答-------------------- 试试:
from T
order by 1
SQL SERVER :
select tt.i, case when 8 then 4 else tt.i end
from
(
select isnull(t.i,0)
from t
order by t.i
) tt
order by tt.i --------------------编程问答-------------------- 题意有误啊 --------------------编程问答-------------------- 你这个题如果没写错的话就是取行号了,取行号需要用子查询,要不需要临时表,一条SQL 语句搞不定,除非DBMS本身有系统函数。 --------------------编程问答-------------------- select (case when isnull(i,0)>4 then 4 else isnull(i,0) end) as i
from Tb
order by i --------------------编程问答-------------------- 没看懂
补充:.NET技术 , C#