select wo.workorderid "request id",
max(wo.title) "subject",
max(qd.queuename) "group",
max(std.statusname) "request status",
max(pd.priorityname) "priority",
max(sdo.name) "site",
max(wo.createdtime) "created time",
max(wos.last_tech_update) "last updte time",
max(notes.notestext) "last note"
from workorder wo
left join sitedefinition sitedef on wo.siteid=sitedef.siteid
left join sdorganization sdo on sitedef.siteid=sdo.org_id
left join workorderstates wos on wo.workorderid=wos.workorderid
left join statusdefinition std on wos.statusid=std.statusid
left join prioritydefinition pd on wos.priorityid=pd.priorityid
left join workorder_queue woq on wo.workorderid=woq.workorderid
left join queuedefinition qd on woq.queueid=qd.queueid
left join workorder_fields wof on wo.workorderid=wof.workorderid
left join workordernotes won on wo.workorderid= won.workorderid
left join notes on notes.notesid=won.notesid
where (wo.isparent='1') and notes.notesid= (select max(nts.notesid) from notes nts where nts.NOTESID=notes.NOTESID ) AND wo.CREATEDTIME >= <from_thisweek> AND wo.CREATEDTIME <= <to_thisweek>
group by wo.workorderid