postgresql7.4
select eg.grade_id,
eg.item_id,
eg.grade_name,
eg.comments,
eg.weight
from evaluation_gradesx eg, acs_objects ao
where content_revision__is_live(eg.grade_id) = true
and eg.item_id = ao.object_id
and ao.context_id = :package_id
$orderby
select coalesce(sum(weight),0) as total_weight
from evaluation_gradesi
where content_revision__is_live(grade_id) = true
and context_id = :package_id