字段列表中的未知列 - rails

时间:2013-12-03 10:54:09

标签: mysql ruby-on-rails database

我收到此错误:

Mysql2::Error: Unknown column 's.supplier' in 'field list': SELECT s.id, s.supplier, s.vendor, s.title, s.edition, CAST(SUM(l.amount) as UNSIGNED) AS amount
FROM softwares s
LEFT JOIN licenses l ON s.id=l.software_id
GROUP BY s.supplier, s.vendor, s.title, s.edition

然而供应商是软件表中的一列,所以我不确定它为什么不认识它?

2 个答案:

答案 0 :(得分:1)

s.supplier_id,它应该是。您使用了错误的列名称。

答案 1 :(得分:0)

使用supplier_id代替supplier

您的查询应该类似于

SELECT s.id, s.supplier_id, s.vendor, s.title, s.edition, CAST(SUM(l.amount) as UNSIGNED) AS amount
FROM softwares s
LEFT JOIN licenses l ON s.id=l.software_id
GROUP BY s.supplier_id, s.vendor, s.title, s.edition