File size: 12,929 Bytes
778d47d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
You are SQL Tutor that validates the student query. Given a database schema, a question, and SQL query generated by student and its response in database. Check the SELECT part of the query and analyse if it's correct or not.
Examples:
database schema :
table weather , columns = [ weather.tmin ( integer | comment : temperature min | values : 31 , 11 ) , weather.station_nbr ( integer | primary key | comment : station number | values : 1 , 2 ) , weather.tmax ( integer | comment : temperature max | values : 52 , 50 ) , weather.date ( date | primary key | values : 2012-01-01 , 2012-01-02 ) , weather.tavg ( integer | comment : temperature average | values : 42 , 41 ) , weather.heat ( integer | values : 23 , 24 ) , weather.cool ( integer | values : 0 , 5 ) , weather.sunrise ( text | values : 07:16:00 , 07:15:00 ) , weather.sunset ( text | values : 16:26:00 , 16:27:00 ) , weather.depart ( integer | comment : departure from normal | values : 16 , 12 ) ]
table relation , columns = [ relation.station_nbr ( integer | comment : station number | values : 1 , 14 ) , relation.store_nbr ( integer | primary key | comment : store number | values : 1 , 2 ) ]
table sales_in_weather , columns = [ sales_in_weather.date ( date | primary key | values : 2012-01-01 , 2012-01-02 ) , sales_in_weather.store_nbr ( integer | primary key | comment : store number | values : 1 , 2 ) , sales_in_weather.units ( integer | values : 0 , 29 ) , sales_in_weather.item_nbr ( integer | primary key | comment : item number | values : 1 , 2 ) ]
foreign keys :
relation.station_nbr = weather.station_nbr
relation.store_nbr = sales_in_weather.store_nbr

Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
weather.date ( 2014-04-28 )
weather.cool ( 7 )
weather.depart ( 7 )
relation.station_nbr ( 7 )
relation.store_nbr ( 7 )
sales_in_weather.date ( 2014-04-28 )
sales_in_weather.store_nbr ( 7 )
sales_in_weather.units ( 7 )
sales_in_weather.item_nbr ( 7 )

Question: Tell the temperature range of the home weather station of store no.7 on 2014/4/28.

SQL query: SELECT tmax - tmin FROM weather INNER JOIN relation ON weather.station_nbr = relation.station_nbr WHERE relation.store_nbr = 7 AND weather.`date` = '2014-04-28'

Execution response [written in pandas format]:
    0
0  34

Feedback:
SELECT.
1. Based on the SQL query, the query selects: [tmax, tmin]
2. The question asks for ['the temperature range']
3. Based on the question, the query should select: [weather.tmax, weather.tmin]
4. Compare 1. and 3., The SQL query selects correct columns, and in correct order.
5. Conclude: correct.
=========
database schema :
table movies , columns = [ movies.director_name ( text | values : Esteban Sapir , Oskar Roehler ) , movies.movie_popularity ( integer | values : 105 , 23 ) , movies.movie_id ( integer | primary key | values : 1 , 2 ) , movies.movie_title ( text | values : La Antena , Elementary Particles ) , movies.director_id ( text | values : 131 , 73 ) , movies.movie_release_year ( integer | values : 2007 , 2006 ) , movies.movie_url ( text ) , movies.movie_title_language ( text | values : en ) , movies.director_url ( text ) , movies.movie_image_url ( text ) ]
table ratings , columns = [ ratings.movie_id ( integer | values : 1066 , 1067 ) , ratings.rating_score ( integer | values : 3 , 2 ) , ratings.rating_id ( integer | values : 15610495 , 10704606 ) , ratings.user_id ( integer | values : 41579158 , 85981819 ) , ratings.critic ( text ) , ratings.rating_url ( text ) , ratings.rating_timestamp_utc ( text | values : 2017-06-10 12:38:33 , 2014-08-15 23:42:31 ) , ratings.critic_likes ( integer | values : 0 , 1 ) , ratings.critic_comments ( integer | values : 0 , 2 ) , ratings.user_trialist ( integer | values : 0 , 1 ) ]
table lists , columns = [ lists.list_title ( text | values : Headscratchers ) , lists.list_movie_number ( integer | values : 5 , 3 ) , lists.list_description ( text ) , lists.list_id ( integer | primary key | values : 1 , 2 ) , lists.user_id ( integer | values : 88260493 , 45204418 ) , lists.list_comments ( integer | values : 3 , 2 ) , lists.list_url ( text ) , lists.list_followers ( integer | values : 5 , 1 ) , lists.list_third_image_url ( text ) , lists.list_cover_image_url ( text ) ]
table ratings_users , columns = [ ratings_users.user_id ( integer | values : 41579158 , 68654088 ) , ratings_users.user_subscriber ( integer | values : 0 , 1 ) , ratings_users.user_trialist ( integer | values : 0 , 1 ) , ratings_users.user_has_payment_method ( integer | values : 0 , 1 ) , ratings_users.user_eligible_for_trial ( integer | values : 1 , 0 ) , ratings_users.rating_date_utc ( text | values : 2017-06-10 , 2012-10-02 ) , ratings_users.user_cover_image_url ( text ) , ratings_users.user_avatar_image_url ( text ) ]
table lists_users , columns = [ lists_users.list_id ( integer | primary key | values : 192287 , 192313 ) , lists_users.user_id ( integer | primary key | values : 2385 , 15264 ) , lists_users.user_trialist ( integer | values : 1 , 0 ) , lists_users.user_has_payment_method ( text | values : 1 , 0 ) , lists_users.user_subscriber ( integer | values : 1 , 0 ) , lists_users.user_eligible_for_trial ( text | values : 0 , 1 ) , lists_users.user_avatar_image_url ( text ) , lists_users.user_cover_image_url ( text ) , lists_users.list_creation_date_utc ( text | values : 2009-12-18 , 2010-01-30 ) , lists_users.list_update_date_utc ( text | values : 2019-11-26 , 2020-05-01 ) ]
foreign keys :
lists.user_id = lists_users.user_id
ratings_users.user_id = lists_users.user_id
lists_users.user_id = lists.user_id
lists_users.list_id = lists.list_id
ratings.user_id = ratings_users.user_id
ratings.rating_id = ratings.rating_id
ratings.user_id = lists_users.user_id
ratings.movie_id = movies.movie_id

Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
movies.director_name ( Christopher Nolan )
movies.movie_title ( The Average , Score )
ratings.critic ( average , AVERAGE , Christopher! , score , Nolan. )
lists.list_title ( CHRISTOPHER NOLAN , christopher nolan , Christopher nolan , Christopher Nolan , Christopher NOLAN , Directed By , average , rating , Nolan , Numbers , Score , movies )

Question: What is the average popularity of each movie that was directed by Christopher Nolan? Indicate which movie directed by him has received the highest number of 5 rating scores.

SQL query: SELECT avg(movies.movie_popularity), movies.movie_title FROM ratings INNER JOIN movies ON ratings.movie_id = movies.movie_id WHERE movies.director_name = 'Christopher Nolan' GROUP BY movies.movie_title ORDER BY count(ratings.rating_score) DESC LIMIT 1

Execution response [written in pandas format]:
        0                1
0  6776.0  The Dark Knight

Feedback:
SELECT.
1. Based on the SQL query, the SQL query selects: [movies.movie_popularity, movies.movie_title]
2. The question asks for ['movie popularity']
3. Based on the question, the query should select: [movies.movie_popularity]
4. Compare 1. and 3., the SQL query selects unnecessary columns [movies.movie_title].
5. Conclude: incorrect.
=========
database schema :
table master , columns = [ master.firstnhl ( text | comment : first nhl season | values : 1997 , 1943 ) , master.birthcountry ( text | values : Finland , Canada ) , master.playerid ( text | values : aaltoan01 , abbeybr01 ) , master.namegiven ( text | values : Antti , Bruce ) , master.lastname ( text | values : Aalto , Abbey ) , master.birthyear ( text | values : 1975 , 1951 ) , master.namenick ( text | comment : nickname | values : Preacher , Taffy ) , master.firstname ( text | values : Antti , Bruce ) , master.lastnhl ( text | comment : last nhl season | values : 2000 , 1943 ) , master.birthday ( text | values : 4 , 18 ) ]
table scoring , columns = [ scoring.playerid ( text | values : aaltoan01 , abbeybr01 ) , scoring.g ( integer | comment : goals | values : 0 , 3 ) , scoring.tmid ( text | comment : team id | values : ANA , CIN ) , scoring.year ( integer | values : 1997 , 1998 ) , scoring.lgid ( text | comment : league id | values : NHL , WHA ) , scoring.gp ( integer | comment : game played | values : 3 , 73 ) , scoring.pos ( text | comment : position | values : C , D ) , scoring.stint ( integer | values : 1 , 2 ) , scoring.pts ( integer | comment : points | values : 0 , 8 ) , scoring.gwg ( text | comment : game-winning goals | values : 0 , 1 ) ]
table teamshalf , columns = [ teamshalf.g ( integer | comment : games | values : 10 , 4 ) , teamshalf.year ( integer | primary key | values : 1916 , 1917 ) , teamshalf.tmid ( text | primary key | comment : team id | values : MOC , MOW ) , teamshalf.lgid ( text | comment : league id | values : NHA , NHL ) , teamshalf.rank ( integer | values : 1 , 3 ) , teamshalf.half ( integer | primary key | values : 1 , 2 ) , teamshalf.w ( integer | comment : wins | values : 7 , 3 ) , teamshalf.gf ( integer | comment : goals for | values : 58 , 31 ) , teamshalf.l ( integer | comment : loses | values : 3 , 7 ) , teamshalf.t ( integer | comment : ties | values : 0 ) ]
table scoringsc , columns = [ scoringsc.playerid ( text | values : adamsbi01 , adamsja01 ) , scoringsc.tmid ( text | comment : team id | values : VML , CAT ) , scoringsc.year ( integer | values : 1920 , 1921 ) , scoringsc.g ( integer | comment : goals | values : 0 , 2 ) , scoringsc.lgid ( text | comment : league id | values : PCHA , WCHL ) , scoringsc.gp ( integer | comment : games played | values : 4 , 5 ) , scoringsc.pts ( integer | comment : points | values : 0 , 3 ) , scoringsc.pos ( text | comment : position | values : R , C ) , scoringsc.a ( integer | comment : assists | values : 0 , 1 ) , scoringsc.pim ( integer | comment : penalty minutes | values : 0 , 6 ) ]
table scoringshootout , columns = [ scoringshootout.playerid ( text | values : adamske01 , afanadm01 ) , scoringshootout.tmid ( text | comment : team id | values : PHO , TBL ) , scoringshootout.g ( integer | comment : goals | values : 0 , 1 ) , scoringshootout.year ( integer | values : 2006 , 2005 ) , scoringshootout.stint ( integer | values : 1 , 2 ) , scoringshootout.gdg ( integer | comment : game deciding goals | values : 0 , 1 ) , scoringshootout.s ( integer | comment : shots | values : 1 , 2 ) ]
table teamssc , columns = [ teamssc.g ( integer | comment : games | values : 3 , 5 ) , teamssc.tmid ( text | primary key | comment : team id | values : QU1 , VA1 ) , teamssc.year ( integer | primary key | values : 1912 , 1913 ) , teamssc.lgid ( text | comment : league id | values : NHA , PCHA ) , teamssc.gf ( integer | comment : goals for | values : 12 , 16 ) , teamssc.w ( integer | comment : wins | values : 1 , 2 ) , teamssc.ga ( integer | comment : goals against | values : 16 , 12 ) , teamssc.t ( integer | comment : ties | values : 0 , 1 ) , teamssc.l ( integer | comment : loses | values : 2 , 1 ) , teamssc.pim ( text | comment : penalty minutes | values : 24 , 20 ) ]
foreign keys :
scoring.playerid = master.playerid
scoringsc.playerid = master.playerid
scoringshootout.playerid = master.playerid

Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
master.birthcountry ( Canada )
master.namenick ( Mean )

Question: How many Canadian players, between the ages of 18 and 24 when they initially played their first NHL, had a cumulative goal total of no more than 5? Indicate their complete names, the year, and the team for which they scored the specified amount of goals.

SQL query: SELECT master.firstname, master.lastname, scoring.tmid, scoring.year FROM master INNER JOIN scoring ON master.playerid = scoring.playerid WHERE master.birthcountry = 'Canada' AND (scoring.g < 5 OR (scoring.g = 5 AND strftime('%Y', scoring.year) - strftime('%Y', master.birthyear) < 18 AND strftime('%Y', scoring.year) - strftime('%Y', master.birthyear) > 24)) GROUP BY master.playerid, master.firstname, master.lastname, scoring.year, scoring.tmid

Execution response [written in pandas format]:
       0       1        2     3    4
0      1   Bruce    Abbey  1975  CIN
1      1  George   Abbott  1943  BOS
2      1     Reg   Abbott  1952  MTL
3      1     Sid     Abel  1938  DET
4      1     Sid     Abel  1939  DET
...   ..     ...      ...   ...  ...
19065  1   Jerry  Zrymiak  1976  MF2
19066  1    Mike     Zuke  1976  IND
19067  1    Mike     Zuke  1984  HAR
19068  1    Mike     Zuke  1985  HAR
19069  1   Wayne      Zuk  1973  EDO

[19070 rows x 5 columns]

Feedback:
SELECT.
1. Based on the SQL query, the query selects: [master.firstname, master.lastname, scoring.tmid, scoring.year]
2. The question asks for ['complete names', 'year', 'team']
3. Based on the question, the query should select: [master.firstname, master.lastname, scoring.year, scoring.tmid]
4. Compare 1. and 3., The SQL query selects correct columns but in wrong order.
5. Conclude: incorrect.