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/