Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created October 2, 2009 21:28
Show Gist options
  • Select an option

  • Save jc00ke/200152 to your computer and use it in GitHub Desktop.

Select an option

Save jc00ke/200152 to your computer and use it in GitHub Desktop.
member select before max/group by
members = db[:customer].
select( :customer__id,
:customer__firstname,
:customer__lastname,
:customer__emailaddress,
:customer__address,
:customer__city,
:customer__state,
:customer__zip,
:customer__customdate1___expirationdate,
:transaction__time___purchasedate,
[[153, 'child'], [154, 'senior'], [588, 'fitness'], [589, 'fitness']].case('annual', :item__id).as(:membershiptype)
).
join(:transaction, :customer__id => :transaction__customerid).
join(:transactionentry, :transaction__transactionnumber => :transactionentry__transactionnumber).
join(:item, :transactionentry__itemid => :item__id).
filter(:transactionentry__itemid => [157, 152, 153, 668, 261, 156, 692, 231, 348, 154, 544, 545, 588, 589, 329, 158, 627, 161, 628, 232, 315, 160, 263, 330]).
filter(:transaction__time => (Date.today - 365)..(Date.today - 335)).
exclude(:customer__id => logged_members).
distinct(:customer__id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment