gpt4 book ai didi

mysql - 使用 MySQL 和 Rails 生成报告 - 如何?

转载 作者:行者123 更新时间:2023-11-30 23:42:29 25 4
gpt4 key购买 nike

这是我的应用程序的数据模型:

id :integer(4) 非空,主键垃圾邮件: bool 值(1)不为空重复: bool 值(1)不为空忽略: bool 值(1)不为空brand_id :整数(4)不为空态度:字符串不为空posted_at:日期时间不为空

态度可以有 3 种状态:消极、积极、中立。

我想以这种方式为开始日期和结束日期之间的每一天生成表中的结果集:

date       | total | positive | neutral | negative2009-10-10 |   12  |     4    |    7    |     1(...)2009-10-30 |   5   |     2    |    1    |     1

并忽略所有具有以下内容的记录:

重复 = 真忽略=真垃圾邮件 = 真

如何实现?

最佳答案

Data.all  :select     => "DATE(posted_at) AS date,
COUNT(*) AS total,
SUM(attitude = 'positive') AS positive,
SUM(attitude = 'neutral') AS neutral,
SUM(attitude = 'negative') AS negative",
:conditions => [ "duplicate <> ? AND ignore <> ? AND spam <> ?",
true, true, true ],
:group => :date,
:order => :date

这应该会为您提供所需的数据;我把它作为练习留给读者将其呈现到表格中。 (SQL 高手:请随时检查我的工作。)

关于mysql - 使用 MySQL 和 Rails 生成报告 - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1876194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com