correted order of todo user stats - best is displayed top

This commit is contained in:
Ulf Gebhardt 2015-06-09 03:18:11 +02:00
parent c8a9ffcbf3
commit 8ce8f717c3

View File

@ -7,13 +7,17 @@ class SYS_SAIMOD_TODO_STATS_USERS extends \SYSTEM\DB\QQ {
//pg
'TODO',
//mys
'SELECT username,
sum(case when state = 0 then 1 else 0 end) state_open,
sum(case when state = 1 then 1 else 0 end) state_closed,
COUNT(*) as count
FROM system_todo_assign
LEFT JOIN system_todo ON system_todo_assign.todo = system_todo.id
LEFT JOIN system_user ON system_todo_assign.user = system_user.id
GROUP BY system_todo_assign.user
ORDER BY count DESC;'
'SELECT *, state_closed/(state_open+state_closed) as best '.
'FROM ('.
'SELECT username,'.
' sum(case when state = 0 then 1 else 0 end) state_open, '.
' sum(case when state = 1 then 1 else 0 end) state_closed, '.
' COUNT(*) as count '.
'FROM system_todo_assign '.
'LEFT JOIN system_todo ON system_todo_assign.todo = system_todo.id '.
'LEFT JOIN system_user ON system_todo_assign.user = system_user.id '.
'GROUP BY system_todo_assign.user '.
'ORDER BY count DESC'.
') a '.
'ORDER BY best DESC;'
);}}