Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn sql-stats-for [db years month users]
(->
(cql/table db :kont_project)
(cql/join
(cql/table db :internaltask)
(cql/where (= :kont_project.taskID :internaltask.id)))
(cql/aggregate [[:sum/hours :as :total]
[:YEAR/date :as :year]
[:internaltask.description :as :task]
[:MONTH/date :as :month]
[:taskID :as :tid]]
[:MONTH/date :taskID])
(cql/select
(cql/where (and
(if (empty? users) nil (in :kont_project.userID users))
(in :kont_project.taskID [5 6 7 8 9 11 12 13 14 15 16 18])
(cqlp/restrict (str " AND YEAR(`kont_project`.`date`) IN (" (apply str (interpose "," (map int years))) ")"))
(cqlp/restrict (str " AND MONTH(`kont_project`.`date`) IN (" (apply str (interpose "," (map int month))) ")")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.