添加“ 1作为变量”时如何解决选择查询导轨中的虚拟属性错误

时间:2019-06-13 15:22:52

标签: sql ruby-on-rails postgresql ruby-on-rails-5

当我想成为此查询时:

Documentos.select("estaciones, 1 as totalPruebas, 1 as totalFilas, 1 as totalPreguntas, '' as nombreColegio").where("id = #{idUsuario}").order("estaciones")

我得到了以下结果:

  

PG :: SyntaxError:错误:沿“ as”行的错误代码第1行:   SELECT COUNT(estaciones,1作为totalPruebas,1作为totalFila ...                                        ^

: SELECT COUNT(estaciones, 1 as totalPruebas, 1 as totalFilas, 1 as totalPreguntas, '' as nombreColegio") FROM "documentos"

1 个答案:

答案 0 :(得分:0)

当我想使用“ as”重命名列时,添加一个计数,但是我只是Terminales.select(“ estaciones as nombreEstacion”)

PG :: SyntaxError:错误:语法错误“ as» 第1行:SELECT COUNT(终端。,测试为estasion)AS count_termin ...                                             ^ :选择COUNT(terminales。,测试为estasion)。AS count_terminales_all_estacion_as_test,“ terminales”。“ id” AS terminales_id来自“ terminales” GROUP BY“ terminales”。“ id”

谢谢!