yegor256
yegor256

Reputation: 105193

How to use COUNT(column) in Sequel?

I'm trying to build this query:

SELECT name, COUNT(file) AS f FROM user GROUP BY name

This is what I'm doing:

db[:user].select(:name).count(:file).group(:name)

But it doesn't work. How can I add that COUNT(file) AS f to the list of SELECT operands?

Upvotes: 1

Views: 1212

Answers (2)

Arup Rakshit
Arup Rakshit

Reputation: 118289

I think you can write following:

@db[:user].
select{[:name, count(:file___f )]}.
group(:name)

Read the docs:

Upvotes: 1

yegor256
yegor256

Reputation: 105193

This is what I've found:

@db[:user]
  .select(:name)
  .select_more{Sequel.as(count(:user__file), :f)}
  .group(:name)

Works fine :)

Upvotes: 0

Related Questions