mats-sql-bundle / code /validator_data /few_shot_prompt_join.txt
thanhdath's picture
Push code: scripts, slurm sbatch, recipes, utils (v3 + selector series)
778d47d verified
Raw
History Blame Contribute Delete
16.1 kB
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 each part of the query and point out if it's correct or not.
Examples:
database schema :
table frpm , columns = [ frpm.`educational option type` ( text | values : Traditional , Juvenile Court School ) , frpm.`school type` ( text | values : K-12 Schools (Public) , High Schools (Public) ) , frpm.`enrollment (ages 5-17)` ( real | values : 1070.0 , 376.0 ) , frpm.`free meal count (ages 5-17)` ( real | values : 553.0 , 182.0 ) , frpm.`percent (%) eligible free (ages 5-17)` ( real | values : 0.516822429906542 , 0.484042553191489 ) , frpm.cdscode ( text | primary key | values : 01100170109835 , 01100170112607 ) , frpm.`percent (%) eligible free (k-12)` ( real | values : 0.519779208831647 , 0.470886075949367 ) , frpm.`frpm count (ages 5-17)` ( real | values : 702.0 , 182.0 ) , frpm.`free meal count (k-12)` ( real | values : 565.0 , 186.0 ) , frpm.`percent (%) eligible frpm (k-12)` ( real | values : 0.657773689052438 , 0.470886075949367 ) ]
table schools , columns = [ schools.edopsname ( text | comment : educational option name | values : Traditional , Juvenile Court School ) , schools.edopscode ( text | comment : education option code | values : TRAD , JUV ) , schools.doctype ( text | comment : the district ownership code type | values : State Special Schools ) , schools.soctype ( text | comment : school ownership code type | values : K-12 Schools (Public) , High Schools (Public) ) , schools.soc ( text | comment : school ownership code | values : 65 , 66 ) , schools.cdscode ( text | primary key | values : 01100170000000 , 01100170109835 ) , schools.eilname ( text | comment : educational instruction level name | values : High School ) , schools.eilcode ( text | comment : educational instruction level code | values : ELEMHIGH , HS ) , schools.school ( text | values : FAME Public Charter ) , schools.virtual ( text | values : P , N ) ]
table satscores , columns = [ satscores.rtype ( text | values : D , S ) , satscores.cds ( text | primary key | values : 10101080000000 , 10101080109991 ) , satscores.dname ( text | comment : district name | values : Alameda Unified ) , satscores.cname ( text | comment : county name | values : Alameda , Amador ) , satscores.sname ( text | comment : school name | values : FAME Public Charter ) , satscores.numge1500 ( integer | comment : number of test takers whose total sat scores are greater or equal to 1500 | values : 14 , 9 ) , satscores.enroll12 ( integer | comment : enrollment (1st-12nd grade) | values : 398 , 62 ) , satscores.numtsttakr ( integer | comment : number of test takers | values : 88 , 17 ) , satscores.avgscrread ( integer | comment : average scores in reading | values : 418 , 503 ) , satscores.avgscrmath ( integer | comment : average scores in math | values : 418 , 546 ) ]
foreign keys :
frpm.cdscode = schools.cdscode
satscores.cds = schools.cdscode
Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
frpm.`educational option type` ( Continuation School )
schools.edopsname ( Continuation School )
schools.school ( Continuation School )
Question: Please list the lowest three eligible free rates for students aged 5-17 in continuation schools.
SQL query: SELECT frpm.`free meal count (ages 5-17)` / frpm.`enrollment (ages 5-17)` FROM frpm INNER JOIN schools ON frpm.cdscode = schools.cdscode WHERE schools.edopsname = 'Continuation School' ORDER BY frpm.`free meal count (ages 5-17)` / frpm.`enrollment (ages 5-17)` LIMIT 3
Execution response [written in pandas format]:
0
0 None
1 None
2 None
Feedback:
JOIN.
- The SQL query uses tables ['frpm', 'schools'], joining them on foreign keys ['frpm.cdscode = schools.cdscode'].
- Based on the question, the query should uses tables ['frpm'].
- The SQL query uses unnecessary tables ['schools'].
- Compare with the foreign keys in database schema ['frpm.cdscode = schools.cdscode'], The SQL query uses correct foreign keys.
- Conclude: incorrect.
=========
database schema :
table schools , columns = [ schools.cdscode ( text | primary key | values : 01100170000000 , 01100170109835 ) , schools.website ( text | values : www.acoe.org , www.envisionacademy.org/ ) , schools.county ( text | values : Alameda , Alpine ) , schools.edopscode ( text | comment : education option code | values : TRAD , JUV ) , schools.edopsname ( text | comment : educational option name | values : Traditional , Juvenile Court School ) , schools.school ( text | values : FAME Public Charter ) , schools.gsserved ( text | comment : grade span served. | values : K-12 , 9-12 ) , schools.district ( text ) , schools.eilcode ( text | comment : educational instruction level code | values : ELEMHIGH , HS ) , schools.gsoffered ( text | comment : grade span offered | values : K-12 , 9-12 ) ]
table satscores , columns = [ satscores.numtsttakr ( integer | comment : number of test takers | values : 88 , 17 ) , satscores.cname ( text | comment : county name | values : Alameda , Amador ) , satscores.cds ( text | primary key | values : 10101080000000 , 10101080109991 ) , satscores.numge1500 ( integer | comment : number of test takers whose total sat scores are greater or equal to 1500 | values : 14 , 9 ) , satscores.dname ( text | comment : district name | values : Alameda Unified ) , satscores.sname ( text | comment : school name | values : FAME Public Charter ) , satscores.enroll12 ( integer | comment : enrollment (1st-12nd grade) | values : 398 , 62 ) , satscores.rtype ( text | values : D , S ) , satscores.avgscrwrite ( integer | comment : average scores in writing | values : 417 , 505 ) , satscores.avgscrread ( integer | comment : average scores in reading | values : 418 , 503 ) ]
table frpm , columns = [ frpm.`county name` ( text | values : Alameda , Alpine ) , frpm.`county code` ( text | values : 01 , 02 ) , frpm.cdscode ( text | primary key | values : 01100170109835 , 01100170112607 ) , frpm.`school code` ( text | values : 0109835 , 0112607 ) , frpm.`school name` ( text | values : FAME Public Charter ) , frpm.`district name` ( text ) , frpm.`district code` ( integer | values : 10017 , 31609 ) , frpm.`frpm count (k-12)` ( real | values : 715.0 , 186.0 ) , frpm.`school type` ( text | values : K-12 Schools (Public) , High Schools (Public) ) , frpm.`frpm count (ages 5-17)` ( real | values : 702.0 , 182.0 ) ]
foreign keys :
frpm.cdscode = schools.cdscode
satscores.cds = schools.cdscode
Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
schools.county ( Los Angeles )
schools.school ( Los Angeles County ROP )
schools.district ( Los Angeles County ROP )
satscores.cname ( Los Angeles )
frpm.`county name` ( Los Angeles )
Question: What are the webpages for the Los Angeles County school that has between 2,000 and 3,000 test takers?
SQL query: SELECT DISTINCT schools.website FROM satscores INNER JOIN schools ON satscores.sname = schools.school WHERE schools.county = 'Los Angeles' AND satscores.numtsttakr BETWEEN 2000 AND 3000
Execution response [written in pandas format]:
Empty DataFrame
Columns: []
Index: []
Feedback:
JOIN.
- The SQL query uses tables ['satscores', 'schools'], joining them on foreign keys ['satscores.sname = schools.school'].
- Based on the question, the query should uses tables ['satscores', 'schools'].
- The SQL query uses correct tables.
- Compare with the foreign keys in database schema ['satscores.cds = schools.cdscode'], The SQL query uses wrong foreign keys.
- Conclude: incorrect.
=========
database schema :
table circuits , columns = [ circuits.circuitid ( integer | primary key | values : 23 , 61 ) , circuits.circuitref ( text | comment : circuit reference name | values : sepang , bahrain ) , circuits.name ( text ) , circuits.location ( text | values : Kuala Lumpur , Sakhir ) , circuits.url ( text ) , circuits.country ( text | values : Malaysia , Bahrain ) , circuits.alt ( integer ) , circuits.lat ( real | comment : latitude | values : 2.76083 , 26.0325 ) , circuits.lng ( real | comment : longitude | values : 101.738 , 50.5106 ) ]
table races , columns = [ races.circuitid ( integer | values : 1 , 2 ) , races.raceid ( integer | primary key | values : 837 , 833 ) , races.name ( text | values : Australian Grand Prix , Malaysian Grand Prix ) , races.round ( integer | values : 1 , 2 ) , races.year ( integer | values : 2009 , 2008 ) , races.date ( date | values : 2009-03-29 , 2009-04-05 ) , races.url ( text ) , races.time ( text | values : 06:00:00 , 09:00:00 ) ]
table results , columns = [ results.raceid ( integer | values : 18 , 19 ) , results.driverid ( integer | values : 1 , 2 ) , results.points ( real | values : 10.0 , 8.0 ) , results.resultid ( integer | primary key | values : 1 , 2 ) , results.number ( integer | values : 22 , 3 ) , results.constructorid ( integer | values : 1 , 2 ) , results.statusid ( integer | values : 1 , 11 ) , results.position ( integer | values : 1 , 2 ) , results.grid ( integer | values : 1 , 5 ) , results.time ( text | values : 1:34:50.616 , +5.478 ) ]
table drivers , columns = [ drivers.driverid ( integer | primary key | values : 452 , 625 ) , drivers.driverref ( text | comment : driver reference name | values : hamilton , heidfeld ) , drivers.forename ( text | values : Lewis , Nick ) , drivers.number ( integer | values : 44 , 6 ) , drivers.code ( text | values : HAM , HEI ) , drivers.url ( text ) , drivers.surname ( text | values : Hamilton , Heidfeld ) , drivers.nationality ( text | values : British , German ) , drivers.dob ( date | comment : date of birth | values : 1985-01-07 , 1977-05-10 ) ]
table driverstandings , columns = [ driverstandings.raceid ( integer | comment : constructor reference name | values : 18 , 19 ) , driverstandings.driverid ( integer | values : 1 , 2 ) , driverstandings.driverstandingsid ( integer | primary key | values : 1 , 2 ) , driverstandings.points ( real | values : 10.0 , 8.0 ) , driverstandings.wins ( integer | values : 1 , 0 ) , driverstandings.position ( integer | values : 1 , 2 ) , driverstandings.positiontext ( text | values : 1 , 2 ) ]
table constructors , columns = [ constructors.name ( text | values : AFM , AGS ) , constructors.constructorid ( integer | primary key | values : 147 , 39 ) , constructors.constructorref ( text | comment : constructor reference name | values : mclaren , bmw_sauber ) , constructors.url ( text ) , constructors.nationality ( text | values : British , German ) ]
foreign keys :
races.circuitid = circuits.circuitid
driverstandings.driverid = drivers.driverid
driverstandings.raceid = races.raceid
results.constructorid = constructors.constructorid
results.driverid = drivers.driverid
results.raceid = races.raceid
Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
circuits.circuitref ( sepang )
drivers.forename ( Michael , Max )
drivers.code ( WIN )
drivers.surname ( Schumacher )
Question: How many times did Michael Schumacher won from races hosted in Sepang International Circuit?
SQL query: SELECT count(driverstandings.driverid) FROM races INNER JOIN driverstandings ON races.raceid = driverstandings.raceid INNER JOIN drivers ON driverstandings.driverid = drivers.driverid WHERE drivers.forename = 'Michael' AND drivers.surname = 'Schumacher' AND races.circuitid = ( SELECT circuitid FROM circuits WHERE circuitref = 'sepang' ) ORDER BY driverstandings.points DESC LIMIT 1
Execution response [written in pandas format]:
0
0 11
Feedback:
JOIN.
- The SQL query uses tables ['races', 'driverstandings', 'drivers'], joining them on foreign keys ['races.raceid = driverstandings.raceid', 'driverstandings.driverid = drivers.driverid'].
- Based on the question, the query should uses tables ['drivers', 'driverstandings', 'races', 'circuits'].
- The SQL query misses tables ['circuits'].
- Compare with the foreign keys in database schema ['driverstandings.driverid = drivers.driverid', 'driverstandings.raceid = races.raceid'], The SQL query uses correct foreign keys.
- Conclude: incorrect.
=========
database schema :
table member , columns = [ member.first_name ( text | values : Angela , Grant ) , member.member_id ( text | primary key | values : rec1x5zBFIqoOuPW8 , rec280Sk7o31iG0Tx ) , member.last_name ( text | values : Sanders , Gilmour ) , member.position ( text | values : Member , Inactive ) , member.email ( text | values : angela.sanders@lpu.edu , grant.gilmour@lpu.edu ) , member.zip ( integer | values : 55108 , 29440 ) , member.phone ( text | values : (651) 928-4507 , 403-555-1310 ) , member.link_to_major ( text | values : recxK3MHQFbR9J5uO , rec7BxKpjJ7bNph3O ) , member.t_shirt_size ( text | values : Medium , X-Large ) ]
table budget , columns = [ budget.spent ( real | values : 67.81 , 121.14 ) , budget.amount ( integer | values : 75 , 150 ) , budget.budget_id ( text | primary key | values : rec0QmEc3cSQFQ6V2 , rec1bG6HSft7XIvTP ) , budget.category ( text | values : Advertisement , Food ) , budget.remaining ( real | values : 7.19 , 28.86 ) , budget.link_to_event ( text | values : recI43CzsZ0Q625ma , recggMW2eyCYceNcy ) , budget.event_status ( text | values : Closed , Open ) ]
table expense , columns = [ expense.cost ( real | values : 122.06 , 20.2 ) , expense.expense_id ( text | primary key | values : rec017x6R3hQqkLAo , rec1nIjoZKTYayqZ6 ) , expense.link_to_member ( text | values : rec4BLdZHS2Blfp4v , recro8T1MPMwRadVH ) , expense.expense_date ( text | values : 2019-08-20 , 2019-10-08 ) , expense.expense_description ( text | values : Post Cards, Posters , Water, Cookies ) , expense.link_to_budget ( text | values : recvKTAWAFKkVNnXQ , recy8KY5bUdzF81vv ) , expense.approved ( text | values : true ) ]
table income , columns = [ income.amount ( integer | values : 50 , 200 ) , income.link_to_member ( text | values : reccW7q1KkhSKZsea , recTjHY5xXhvkCdVT ) , income.source ( text | values : Dues , Fundraising ) , income.notes ( text ) , income.income_id ( text | primary key | values : rec0s9ZrO15zhzUeE , rec7f5XMQZexgtQJo ) , income.date_received ( text | values : 2019-10-17 , 2019-09-04 ) ]
table attendance , columns = [ attendance.link_to_member ( text | primary key | values : recD078PnS3x2doBe , recP6DJPyi5donvXL ) , attendance.link_to_event ( text | primary key | values : rec2N69DMcrqN9PJC , rec5XDvJLyxDsGZWc ) ]
table zip_code , columns = [ zip_code.type ( text | values : Unique , Standard ) , zip_code.state ( text | values : New York , Puerto Rico ) , zip_code.county ( text | values : Suffolk County , Adjuntas Municipio ) , zip_code.city ( text | values : Holtsville , Adjuntas ) , zip_code.zip_code ( integer | primary key | values : 501 , 544 ) , zip_code.short_state ( text | values : NY , PR ) ]
foreign keys :
attendance.link_to_member = member.member_id
expense.link_to_member = member.member_id
expense.link_to_budget = budget.budget_id
income.link_to_member = member.member_id
member.zip = zip_code.zip_code
Matched contents are written in this format table.column (some values can be found in that column)
matched contents :
member.position ( Member )
zip_code.city ( Money , Max )
Question: List the full name of the top five members who spend the most money in the descending order of spending.
SQL query: SELECT member.first_name, member.last_name FROM member INNER JOIN expense ON member.member_id = expense.link_to_member ORDER BY expense.cost DESC LIMIT 5
Execution response [written in pandas format]:
0 1
0 Elijah Allen
1 Sacha Harrison
2 Sacha Harrison
3 Sacha Harrison
4 Elijah Allen
Feedback:
JOIN.
- The SQL query uses tables ['member', 'expense'], joining them on foreign keys ['member.member_id = expense.link_to_member'].
- Based on the question, the query should uses tables ['expense', 'member'].
- The SQL query uses correct tables.
- Compare with the foreign keys in database schema ['expense.link_to_member = member.member_id'], The SQL query uses correct foreign keys.
- Conclude: correct.