|
|
|
@ -62,7 +62,9 @@ class Management::SchoolDataContrastService
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def query_report_sql(from_sql)
|
|
|
|
|
order_by = "(total = 0 AND other_total != 0) #{sort_direction}, (percentage != 0) #{sort_direction}, percentage #{sort_direction}"
|
|
|
|
|
|
|
|
|
|
"SELECT reports.*, (other_total - total) increase, (IF(other_total - total = 0, 0.0, round((other_total - total) / IF(total = 0, 1, total), 5))) percentage "\
|
|
|
|
|
"FROM (#{from_sql}) reports ORDER BY percentage #{sort_direction} LIMIT #{PAGE_SIZE} OFFSET #{offset}"
|
|
|
|
|
"FROM (#{from_sql}) reports ORDER BY #{order_by} LIMIT #{PAGE_SIZE} OFFSET #{offset}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|