Skip to content

Instantly share code, notes, and snippets.

@radiuscz
Created February 14, 2018 21:54
Show Gist options
  • Save radiuscz/edc8557c7ffc22d6669984601f534616 to your computer and use it in GitHub Desktop.
Save radiuscz/edc8557c7ffc22d6669984601f534616 to your computer and use it in GitHub Desktop.
Intranet Koha: TOP 15 nejaktivnějších čtenářů
select count(*) as Pocet, ctenar as 'Čtenář', branches.branchname as 'Oddělení', itemtypes.description as 'Typ jednotky'
from (
select issuedate, itemnumber, borrowernumber, concat(firstname, " ", surname) as ctenar, old_issues.branchcode
from old_issues
left join borrowers USING(borrowernumber)
UNION
select issuedate, itemnumber, borrowernumber, concat(firstname, " ", surname) as ctenar, issues.branchcode
from issues
left join borrowers USING(borrowernumber)
) as T
LEFT JOIN items USING(itemnumber)
LEFT JOIN branches ON T.branchcode = branches.branchcode
LEFT JOIN itemtypes ON itemtypes.itemtype = items.itype
where issuedate BETWEEN <<Od|date>> AND <<Do|date>>
AND T.branchcode=<<Oddělení|branches>>
AND itype=<<Typ jednotky|itemtypes>>
group by borrowernumber
order by Pocet desc
LIMIT 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment