日期:2014-05-18  浏览次数:20534 次

请问查询SQL语句的写法..
请问查询SQL语句的写法
一表(表名为oaro   )有以下数据:
id         code                                   total       pt
1           20070410140212               20             12
2           20070410140212               20             8
3           20070410140212               20             6
4           20070410140212               20             4
5           20070410140213               50             24
6           20070410140214               35             7
7           20070410140214               35             6
8           20070410140215               62             6
9           20070410140216               13             4

现在我需要查询code不重复的信息,即查询结果是:
id         code  
1           20070410140212
5           20070410140213
6           20070410140214  
8           20070410140215          
9           20070410140216

请问这样的语句应该怎么写?

------解决方案--------------------
select * from oaro as a
where not exists(select 1 from oaro where code=a.code and id <a.id)
------解决方案--------------------
select
t.*
from
oaro t
where
not exists(select 1 from oaro where code=t.code and id <> t.id)