如何在Sequel中放置原始SQL查询

我试图将SQL代码转换为Seqel从我的脚本运行它。 我该怎么转换这个:

select code, count(1) as total from school_districts group by code order by total desc; 

进入续集? 或者,有没有办法将原始SQL传递给续集? school_districts也将插入#{table_name}

您可以通过以下几种方式实现:

  1. 使用[]

     DB["your sql string"] 
  2. 使用fetch

     DB.fetch("your sql string") 
 DB[:school_districts].select(:code).group_and_count(:code).reverse_order(:count) 

是执行该查询的续集方式。 然而,我没有为计数列添加别名,但我希望你能做到这一点。

尽管在Sequel中工作是可取的,因为它允许您在不更改代码的情况下更改DBM,但我更希望您使用fetch方法。