help!!!sql 高手
最近在开发一个小项目,遇到sql难题,问题描述如下:
有一张表记录了部门、班、组、时间1,其中部门、班、组是级联关系,部门里有班,班里有组,该表记录了历史纪录,现在想查询特定班,时间最大的记录集,得到的数目应该和组数相等,如果没有组,就是一条,谢谢大侠帮忙!!!!!!
问题点数:0、回复次数:2Top
1 楼ORARichard(没钱的日子......)回复于 2004-12-04 16:55:36 得分 0
select 部门,班,组,max(时间1) from 表 where 班=特定班 and exists (select 1 from 表 where 班=特定班 and 组 is not null) group by 组
union
select * from 表 where 班=特定班 and 组 is null)Top
2 楼ORARichard(没钱的日子......)回复于 2004-12-04 16:58:42 得分 0
如果不同部门存在相同名称的班,用下面的:
select 部门,班,组,max(时间1) from 表 where 部门=特定部门 and 班=特定班 and exists (select 1 from 表 where 部门=特定部门 and 班=特定班 and 组 is not null) group by 组
union
select * from 表 where 部门=特定部门 and 班=特定班 and 组 is null)Top




