Skip to main content
removed tags from the title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Views 3 : how How do I do a simple GROUP BY?

Tweeted twitter.com/#!/StackDrupal/status/430333229783339008
Source Link
sbrattla
  • 1.2k
  • 1
  • 11
  • 22

Views 3 : how do I do a simple GROUP BY?

I've got a view which represents a list of redirects. The view has two fields:

  1. 'Destination'
  2. 'Source'
  3. 'Hash' (an indexed has based on the destination)

I'd like to generate a view which lists destinations along with the number of times a visitor has been redirected to that destination. If I were to write the SQL myself, I'd simply do:

SELECT destination, count(*) as redirects FROM redirects GROUP BY hash

However, no matter what I do I can't get Views to ONLY group by hash. This is what I've done:

  1. Enabled aggregation (Advanced > Aggregation>
  2. Enabled COUNT on the 'source' field.

What happens now is that Views COUNT on the 'source' field, but groups on both the 'destination' AND 'hash' field:

SELECT destination, hash, COUNT(source) FROM redirects GROUP BY destination, hash

How do I get Views to only GROUP BY the 'hash' field?