| 发表于:2007-03-07 13:15:2714楼 得分:0 |
没有oracle数据库 用sql server 实现了一下,看看对楼主有没有启发: 1.建一个区分大小写的表 create table [test] ( [col1] [varchar] (20) collate chinese_prc_cs_as null , [col2] [varchar] (20) collate chinese_prc_cs_as null , [col3] [varchar] (20) collate chinese_prc_cs_as null ) on [primary] go 2.插入原始数据 insert into test(col1,col2,col3) select 'a ', 'a ', '1 ' union all select 'a ', 'a ', '2 ' union all select 'b ', 'a ', '3 ' union all select 'b ', 'a ', '4 ' union all select 'c ', 'a ', '5 ' union all select 'c ', 'a ', '6 ' union all select 'a ', 'b ', '7 ' union all select 'a ', 'b ', '8 ' union all select 'a ', 'a ', '9 ' union all select 'a ', 'a ', '10 ' union all select 'b ', 'b ', '11 ' union all select 'd ', 'c ', '12 ' union all select 'd ', 'c ', '13 ' union all select 'e ', 'c ', '14 ' union all select 'e ', 'c ', '15 ' 3.选择所需数据 select test.col1,test.col2,test.col3 from test inner join ( select min(col1) as col1, col2 from test where col1 <> col2 group by col2 )t1 on test.col1 <> test.col2 and test.col1=t1.col1 and test.col2=t1.col2 4.结果 col1 col2 col3 -------------------- -------------------- -------------------- a a 1 a a 2 a b 7 a b 8 d c 12 d c 13 (所影响的行数为 6 行) 完! | | |
|