Skip to content

Instantly share code, notes, and snippets.

@LauJensen
Created November 7, 2010 22:32
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 LauJensen/666980 to your computer and use it in GitHub Desktop.
Save LauJensen/666980 to your computer and use it in GitHub Desktop.
clojureql.core> (let [photo-counts (table {} :photos [:user_id [:count:* :as :cnt]])]
(-> (table {} :users [:*])
(join photo-counts (= {:users.user_id :photos.user_id}))
compile))
"SELECT users.*,photos_aggregation.cnt FROM users
LEFT OUTER JOIN
(SELECT photos.user_id,count(photos.*) AS cnt FROM photos GROUP BY user_id)
AS photos_aggregation ON (users.user_id = photos_aggregation.user_id)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment