select y1.id
,(case so.type when '6'then (select id from sys_organization s where s.id=so.parent_id) else so.id end) as orgid
,sc.value
from YH_TROUBLEMANAGE y1,YH_NOCASUALTYTROUBLE y2,sys_organization so,sys_code sc
where y1.id=y2.register_id and y1.troubledept=so.id and y1.TROUBLELEVEL=sc.id
and to_date(to_char(y1.troubledate,'yyyy-mm'),'yyyy-mm')
between to_date('2011-4','yyyy-mm') and to_date('2011-4','yyyy-mm')
我想根据y1.id、orgid、sc.value进行分组查询,该怎么修改我的SQL语句?
select y1.id
,(case so.type when '6'then (select id from sys_organization s where s.id=so.parent_id) else so.id end) as orgid
,sc.value
from YH_TROUBLEMANAGE y1,YH_NOCASUALTYTROUBLE y2,sys_organization so,sys_code sc
where y1.id=y2.register_id and y1.troubledept=so.id and y1.TROUBLELEVEL=sc.id
and to_date(to_char(y1.troubledate,'yyyy-mm'),'yyyy-mm')
between to_date('2011-4','yyyy-mm') and to_date('2011-4','yyyy-mm')
group by
y1.id
,(case so.type when '6'then (select id from sys_organization s where s.id=so.parent_id) else so.id end) as orgid
,sc.value