Created
March 7, 2013 16:42
-
-
Save jaturken/5109499 to your computer and use it in GitHub Desktop.
UsersToPayQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersToPayQuery | |
def self.find | |
# Select users who have no errors in groups, likes and shares, have wmr and have balanse to pay. | |
# A bit strange indentation. But it's easier to read this SQL in console with this indendation. | |
User.where(" | |
NOT EXISTS( | |
SELECT id FROM shares | |
WHERE shares.error = 1 | |
AND shares.declined = false | |
AND shares.user_id = users.id) | |
").where(" | |
NOT EXISTS( | |
SELECT id FROM likes WHERE | |
likes.error = 1 | |
AND likes.declined = false | |
AND likes.user_id = users.id) | |
").where(" | |
NOT EXISTS( | |
SELECT id FROM groups WHERE | |
groups.error = 1 | |
AND groups.declined = false | |
AND groups.user_id = users.id) | |
").where("wmr <>''").where("balance >= #{ AppConfig.payout_min_amount }") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment