首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

急一个检索有关问题()

2012-01-10 
急!!一个检索问题(在线等)select sysno,id,time,department...from table where conditon想取一个这样的结

急!!一个检索问题(在线等)
select sysno,id,time,department...from table where conditon

想取一个这样的结果:min(sysno) and distinct(id,time,department...) 

由于sysno是系统编号,不唯一,所以无法对所有的列名进行distinct检索。
高手请指教!!!
急~~~~~~~~~~~~~~~~~

[解决办法]
--用分组,取sysno的min()

select min(sysno) as sysno,id,time,department...
from table 
where conditon 
group by id,time,department...
[解决办法]

SQL code
 
--你要的是最小的syno 好像是用的是这个
select * from tbl where not exists(select * from tbl where id=a.id and time=a.time and department=a.department and sysno <a.sysno)



[解决办法]
SQL code
--方法一:select a.* from tb a,(select id,time,department,min(sysno) sysno from tb group by id,time,department) bwhere a.id = b.id and a.time = b.time and a.department = b.department and a.sysno = b.sysno--方法二:select a.* from tb a where sysno = (select min(sysno) from tb where id = a.id and time = a.time and department = a.department) 

热点排行