我知道有一些相关的帖子,但我的情况有点不同,我想得到一些帮助.
我需要从数据库中提取一些数据,这些数据是白天的累积交互计数.目前这就是我所拥有的
SELECT
e.Date AS e_date,
count(e.ID) AS num_interactions
FROM example AS e
JOIN example e1 ON e1.Date <= e.Date
GROUP BY e.Date;
Run Code Online (Sandbox Code Playgroud)
这个输出接近我想要的但不完全是我需要的.我遇到的问题是日期存储在交互发生的小时和秒之间,因此group by不会将日期分组在一起.
这就是输出的样子.http://screencast.com/t/N1KFNFyil 12-23 theres 5交互但由于时间戳不同而没有分组.所以我需要找到一种方法来忽略时间戳,只看一天.
如果我尝试GROUP BY DAY(e.Date)它只在一天之前对数据进行分组(即任何月份1日发生的所有事情都被分成一行)并且输出不是我想要的那样http://screencast.com/t/HN6DH3GV63M
GROUP BY DAY(e.Date), MONTH(e.Date) 将月份和月份的日期分开,但计数结束了.
我根本不是MySQL专家所以我对我所缺少的东西感到困惑
如下面的代码所示,在超类中定义类访问器可能会有意外行为,因为类访问器对于所有子类都是相同的变量.
class Super
cattr_accessor :name
end
class SubA < Super; end
class SubB < Super; end
SubA.name = "A"
SubB.name = "B"
SubA.name
=> "B" # unexpected!
Run Code Online (Sandbox Code Playgroud)
我希望每个子类都有一个独立的类访问器,因此可能的解决方案是将cattr_accessor从超类中移出并将其放在每个子类中.
class Super; end
class SubA < Super
cattr_accessor :name
end
class SubB < Super
cattr_accessor :name
end
SubA.name = "A"
SubB.name = "B"
SubA.name
=> "A" # expected!
Run Code Online (Sandbox Code Playgroud)
这个解决方案是一个很好的做法吗?你知道更好的选择吗?
我创建了以下Active Record Migration,它添加和删除了一些索引.
class FixIndexes < ActiveRecord::Migration
def change
add_index :table1, :field1, :unique => true
remove_index :table2, :name => "index_table2_on_field1"
remove_index :table2, :name => "index_table2_on_field2"
remove_index :table3, :name => "index_table3_on_field1"
add_index :table3, [:field1, :field2]
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行migration($ bundle exec rake db:migrate)时,它按预期正常工作.
不幸的是,当我尝试恢复迁移($ bundle exec rake db:rollback)时,它不起作用并引发ActiveRecord::IrreversibleMigration异常
== FixIndexes: reverting =====================================================
rake aborted!
An error has occurred, all later migrations canceled:
ActiveRecord::IrreversibleMigration/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/migration/command_recorder.rb:42:in `block in inverse'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.14/lib/active_record/migration/command_recorder.rb:40:in `map'
Run Code Online (Sandbox Code Playgroud)
我的问题是:
def self.up而def self.down …mysql activerecord ruby-on-rails rails-migrations ruby-on-rails-3
当我使用带有CloudBackendMessaging.TOPIC_ID_BROADCAST的subscribeToCloudMessage()函数作为在CloudBackendFragment.java中完成的topicId时,一切正常但是当我给这个函数我自己的字符串时,我收到以下消息:
错误:
m.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
"code": 400,
"errors": [
{
"domain": "global",
"message": "SubscriptionIDs: String properties must be 500 characters or less. Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length.",
"reason": "badRequest"
}
],
"message": "SubscriptionIDs: String properties must be 500 characters or less. Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length."
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1042)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.google.cloud.backend.core.CloudBackend.list(CloudBackend.java:314)
at com.google.cloud.backend.core.CloudBackendAsync.access$8(CloudBackendAsync.java:1)
at com.google.cloud.backend.core.CloudBackendAsync$9.callBackend(CloudBackendAsync.java:270)
at com.google.cloud.backend.core.CloudBackendAsync$9.callBackend(CloudBackendAsync.java:1)
at …Run Code Online (Sandbox Code Playgroud) 我有以下功能
def map[A,B](l: List[A])(f: A => B): List[B]
def concat[A](l: List[List[A]]): List[A]
Run Code Online (Sandbox Code Playgroud)
我想实现这个
def flatMap[A,B](l: List[A])(f: A => List[B]): List[B]
Run Code Online (Sandbox Code Playgroud)
现在,我知道正确的解决方案是(所以这不是问题)
def flatMap[A,B](l: List[A])(f: A => List[B]): List[B] =
concat(map(l)(f))
Run Code Online (Sandbox Code Playgroud)
但当我试图解决它时,我首先尝试(我忘了连续)
def flatMap[A,B](l: List[A])(f: A => List[B]): List[B] =
map(l)(f)
// compilation output
[error] found : A => fpinscala.datastructures.List[B]
[error] required: A => B
[error] map(l)(f)
Run Code Online (Sandbox Code Playgroud)
我无法理解那个错误,因为看起来评价map(l)(f)是错误的,但事实并非如此,它是flatMap函数的返回值有什么不对.
事实上,如果在两行代码中分解相同的实现,我们可以看到Scala编译器抱怨另一个不同的错误 - 实际上是我在前面的代码中也预期的错误.
def flatMap[A,B](l: List[A])(f: A => List[B]): List[B] = {
var result = map(l)(f)
result
}
// compilation output …Run Code Online (Sandbox Code Playgroud) mysql ×2
activerecord ×1
android ×1
compilation ×1
date ×1
google-maps ×1
group-by ×1
inheritance ×1
java ×1
json ×1
ruby ×1
scala ×1