mysql - 在 mysql 中创建一个 Where 子句

标签 mysql ruby-on-rails activerecord where-clause

find_by_sql("SELECT s.productcode, s.description, CAST(SUM(l.amount) as UNSIGNED) AS amount FROM softwares s LEFT JOIN licenses l ON s.id=l.software_id GROUP BY s.productcode, s.description WHERE s.supplier= 'softcat'")

我目前有这个,我在 SoftwaresController#export_softcat 中收到错误 ActiveRecord::StatementInvalid

我试图在末尾添加一个 where 子句以仅选择特定供应商的记录。

最佳答案

SELECT s.productcode, s.description, CAST(SUM(l.amount) as UNSIGNED) AS amount
FROM softwares s
    LEFT JOIN licenses l ON s.id=l.software_id
WHERE s.supplier = 'softcat'
GROUP BY s.productcode, s.description

这样试试

关于mysql - 在 mysql 中创建一个 Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12071765/

相关文章:

mysql - 在 SELECT WHERE 之前添加表索引并在 INSERT 之前删除它们

mysql - 连接两个表并显示发票号码总金额的 SQL 查询

mysql - ORDER BY 在 MySQL 5.1 中不起作用

ruby-on-rails - Capistrano部署Rails的失败错误- bundle :未找到

activerecord - 运行 rake db :create 时出现 Arel 弃用警告

php - Codeigniter 使用 CURDATE() 选择数据

python - pymysql连接线程安全吗? pymysql游标线程安全吗?

ruby-on-rails - Devise token_authenticatable 已弃用,替代方案是什么?

ruby-on-rails - Rails Route 仅带有数字参数

ruby-on-rails - activerecord has_many :through find with one sql call