ruby之如何执行自己写的SQL
我现在对一张表进行统计,必须执行自己手写的sql语句。比如: select author,count(name) as totalname from wiki where createdate >= '2008-10-01' and createdate <= '2008-10-30' group by author
不知道这样的功能在ruby中如何实现。
因为我是新手,希望能描述的越详细越好,最好能贴一下代码出来。不甚感激!!!
只要能实现此功能,分不够的可以再加!!!!!
[解决办法]
你用的是什么数据库,应该有很多种方法的,参考
http://www.troubleshooters.com/codecorn/ruby/database/index.htm
[解决办法]
sql = "select author,count(name) as totalname from wiki where createdate >= '2008-10-01' and createdate <= '2008-10-30' group by author"
require "dbi"
dbh = DBI.connect("DBI:ODBC:#{db_name}",@user,@password)
sth = dbh.execute(sql)