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

急!!一个检索问题(在线等)
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) b
where 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)