Windows函数语法错误

时间:2015-07-13 05:36:39

标签: ruby-on-rails postgresql

以下是Postgres的Windows语法我在rails中使用:

select *
from (
  select *,row_number() over(partition by category order by random()) as ordinal
  from question) X
where ordinal = 1;

我测试了这个语法,我在rails控制台中给出了它返回

SyntaxError: unexpected tIDENTIFIER, expecting end-of-input
...m ( select *, row_number() over(partition by category order ...
...                               ^

我不知道我的代码有什么问题,以及如何修复它。

这是我的问题控制器:

class QuestionnairesController < ApplicationController

def index
    binding.pry
    @question = Questionnaire.find(params[:category_id])
    @category = Category.find(params[:category_id])
    @videos = VideoClue.find(params[:category_id])
    ###This finds all the questions from the question table by their category_id. Whenever I select a category, it matches the question related to the category

    render :show
    ###render :show Renders Html page
end

def choose_answer

    @question = Questionnaire.find(params[:id])
    @choices = @question.choices
    #list all from the choices column

    render :choose_answer

end

def results

    @question_data= Questionnaire.where(id: params[:id])
    @correct_answer = @question_data[0].correct_answer
    @selected_answer = params[:choice]
    #In order to compare the user selected answer to the right answer, I had to make 'choice' as a param and created a variable that is equal to the params so it will render the success and error pages correctly.

    if @selected_answer == @correct_answer
        render :success
    else
        render :error
    end












    end





end

我的问题表:

Questionnaire.create({question: "In what year did MTV (Music Television) premiere and what was the first music video the channel aired?", choices:['1982 Michael Jackson Bille Jean', '1984 Madonna Like a virgin', '1981 The Buggles Video Killed The Radio Star'], correct_answer:"1981 The Buggles Video Killed The Radio Star", category_id:1})
Questionnaire.create({question:"This game launched in 1991 on Sega Genesis which the player's mission is to collect as many golden rings as possible", choices:['Battletoads', 'Sonic The Hedgehog', 'Jewel Master'], correct_answer: "Sonic The Hedgehog", category_id:1})
Questionnaire.create({question: "This sitcom featured four girls living under one roof. They attended the same boarding school, ran a shop together and reside in a town called Peekskill." , choices:['Designing Women', 'The Facts of Life', 'Girlfriends'], correct_answer:'The Facts of Life', category_id: 2})
Questionnaire.create({question: "This martial arts film premiere in 1985 which featured a young man who studies Bruce Lee's techniques while on the search for his master. This was set in New York City." , choices:['The Last Dragon', 'The Karate Kid', 'Big Trouble in Little China'], correct_answer:'The Last Dragon', category_id: 3})
Questionnaire.create({question:"This game launched in 1991 on Sega Genesis which the player's mission is to collect as many golden rings as possible", choices:['Battletoads', 'Sonic The Hedgehog', 'Jewel Master'], correct_answer: "Sonic The Hedgehog", category_id:4})

我的窗口语法在哪里?

0 个答案:

没有答案