Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement query k, closes #20

  • Loading branch information...
commit f25302ab805ad54e234bea11423ca6d3d5c34db8 1 parent 38f95ba
@nddrylliog authored
Showing with 65 additions and 1 deletion.
  1. +32 −0 nba/app/views/query/k.html.erb
  2. +33 −1 queries/basic_k.sql
View
32 nba/app/views/query/k.html.erb
@@ -0,0 +1,32 @@
+<div class=row-fluid>
+ <div class=span6>
+ <h2>Result of query <%= params[:action].upcase %></h2>
+ <p>
+ List the last and first name of the players who played for a Chicago team and Houston team.
+ </p>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th scope=col>#</th>
+ <th scope=col>First Name</th>
+ <th scope=col>Last Name</th>
+ </tr>
+ </thead>
+ <tbody>
+ <%- while line = @results.fetch() -%>
+ <tr>
+ <th scope=row><%= link_to(
+ line[0],
+ :controller => "person",
+ :action => "player",
+ :id => line[0]
+ ) %></th>
+ <td><%= line[1] %></td>
+ <td><%= line[2] %></td>
+ </tr>
+ <%- end -%>
+ </tbody>
+ </table>
+ </div>
+ <%= render :partial => "sql" %>
+</div>
View
34 queries/basic_k.sql
@@ -1,4 +1,36 @@
-- List the last and first name of the players who played for a Chicago team
-- and Houston team.
--- STUB
+CREATE OR REPLACE VIEW played_in_chicago AS
+ SELECT
+ person_id
+ FROM
+ player_seasons ps
+ JOIN teams t on ps.team_id = t.id AND t.trigram = 'CHI'
+;
+
+CREATE OR REPLACE VIEW played_in_houston AS
+ SELECT
+ person_id
+ FROM
+ player_seasons ps
+ JOIN teams t on ps.team_id = t.id AND t.trigram = 'HOU'
+;
+
+SELECT
+ p.id, firstname, lastname
+FROM
+ (
+ SELECT
+ *
+ FROM
+ played_in_chicago
+ INTERSECT
+ SELECT
+ *
+ FROM
+ played_in_houston
+ )
+ JOIN people p on p.id = person_id
+;
+
Please sign in to comment.
Something went wrong with that request. Please try again.