Question: A question that I hope you can answer for a Q&A app. Still very new with Rails. It should be fairly simple but there is a small issue that I run into whenever I am trying to create a list of links to show up that point to a RESTful route from a loop. 

Here's the code for the controller:

users\_controller.rb

```
def list
  @user = User.find(params[:id])
  @users = User.find(:all, :select => :name)
end

def quiz
  @user = User.find(params[:id])
  @users = User.find(:all, :select => :name)
end

```

Here's the code for the view:

```
<% if current_user.admin? %>
  <ul>
    <%- @users.each do |link| %>
      <li><%= link_to link.name, quiz_user_path(@user, @quiz) %></li>
    <% end %>
  </ul>
<% end %>

```

Here's the code for the route:

```
resources :users do 
  get 'quiz', :on => :member
end

```

What I want to do is generate individual links based on the name of the users and then link to the quiz page for that specific user. I'm pretty sure that something needs to be changed for the code in my view. Right now, all I'm getting is a link that all points to the current user which in this case is user 4. (`http://localhost:3000/users/4/quiz`)

Thanks for any quick tips to solve this.

Answer: 
```
-- select 
select HighTemp, LogDate,(select AVG(HighTemp) 
                          from tbl where 
                          DATEDIFF(MONTH, LogDate, t1.LogDate) between 0 and 6)
from tbl t1

-- update
update t1 set Temp6MonthHighAverage = (select AVG(HighTemp) 
                          from tbl where 
                          DATEDIFF(MONTH, LogDate, t1.LogDate) between 0 and 6)
from tbl t1

```
You can certainly do this with a simple UPDATE:

```
UPDATE table SET Temp6MonthHighAverage = 
  (SELECT AVG(HighTemp) FROM table t2 WHERE
     t2.LogDate <= table.LogDate
     AND t2.LogDate > DATEADD(m, -6, table.LogDate)
  )

```

To avoid re-calculating constantly (since the past will not change), just add a `WHERE Temp6MonthHighAverage IS NULL` at the end and the same UPDATE can be run as needed to fill in the gaps as new dates are added.