Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created October 27, 2011 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Licenser/f8a9496b3173dffc62c2 to your computer and use it in GitHub Desktop.
Save Licenser/f8a9496b3173dffc62c2 to your computer and use it in GitHub Desktop.
(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