收集的又一道有趣的SQL题
作者: 三十而立时间:2009年10月15日 21:59:51本文出自 “inthirties(三十而立)”博客,转载请务必注明作者和保留出处http://blog.csdn.net/inthirties/archive/2009/10/15/4673268.aspx 把次序不对的列找出来 请问 下面的表该如何排序?我有下面的表。次序如下 其中第5个记录和第6条记录次序颠倒了。这个表数据量比较大。 用什么方法可以对这个表中的 b列排序。使其能够按照升序排列。
a b
1 #1杆塔
2 #2杆塔
3 #3.1杆塔
4 #3.2杆塔
5 #5杆塔
6 #4杆塔
7 #6杆塔
8 #7杆塔
9 #9杆塔
10 #8杆塔
现在要做的事情就是把 次序不对的列找出来。 不是排序。比如上列中b列第5,第6列。第9,10次序不对。 现在要把其中的列找出来。
5 #5杆塔
6 #4杆塔
9 #9杆塔
10 #8杆塔
就是把这样的列能够找出来。 SQL> with temp as(
2 select 1 a, '#1杆塔' b from dual union all
3 select 2 a, '#2杆塔' b from dual union all
4 select 3 a, '#3.1杆塔' b from dual union all
5 select 4 a, '#3.2杆塔' b from dual union all
6 select 5 a, '#5杆塔' b from dual union all
7 select 6 a, '#4杆塔' b from dual
8 ) select a, b from (select temp.*, row_number() over(order by a asc) a_ord,r
ow_number() over(order by to_number(substr(b, 2, length(b)-3)) asc) b_ord from t
emp) t where t.a_ord <>t.b_ord;
A B
---------- --------
6 #4杆塔
5 #5杆塔
如果没有那句“三十而立”,三十岁的男人正可以轻轻松松 专业论坛 http://www.inthirties.com 技术博客 http://blog.csdn.net/inthirties 个人站点 http://blog.inthirties.com Oracle Mysql技术论坛| 打造实用的Oracle Mysql技术交流园地
相关文档:
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *, char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......
/*dialect*/
With Cust AS
( SELECT fnumber,
ROW_NUMBER() OVER (order by id) as RowNumber
from t_bd_currency)
select *
from Cust
Where RowNumber Between 20 and 30
//
  ......
今天,有一个sql NOT IN语句,匹配条件里有一个null,结果什么都查不出来,同事觉得很难理解。其实只要明白一点就可以了,IN语句匹配的时候是用=,NOT IN匹配的时会用<>,就很容易理解了。
首先我们要知道,null在oracle是个特殊的东西,没有任何可比性,如果使用 =/<> 对比null,得到的始终是false。n ......
用下面的视图:
SQL> desc user_col_comments;
Name Null? Type
------------------------------- -------- ----
TABLE_NAME &nbs ......