Skip to content

Instantly share code, notes, and snippets.

@derekharmel
Created May 25, 2017 19:32
Show Gist options
  • Save derekharmel/6797e2a9e73ff1310d8ee3486a0e5e85 to your computer and use it in GitHub Desktop.
Save derekharmel/6797e2a9e73ff1310d8ee3486a0e5e85 to your computer and use it in GitHub Desktop.
# Greetings SQL Guru!
#
# The task is to write code that mimics the computation of a few SQL queries.
# Don't worry, you don't have to write a parser! Just read in a comma delimited
# flat file 'input.txt' and output the results of the following queries:
#
# select state,count(*) from table group by state order by count(*) desc
# select round(avg(age),1) from table
# select state,round(avg(age),0) from table group by state order by avg(age)
# select state,round(avg(age),0) from table where age > 15 AND age < 55 group by state order by state
#
# The output of your solution will be diff'd with the contents of 'output.txt'
#
# You can write the solution in any language provided that any compilation or setup is
# done in the 'build' script and the command to run the solution is named 'sql'.
name,age,state
Sam,20,VA
Joe,20,VA
Sally,18,MD
Sam,24,FL
Jake,12,CO
Sue,49,MA
Larry,55,CO
Bob,99,WA
Jess,21,MD
Tom,30,VA
VA,3
MD,2
CO,2
FL,1
MA,1
WA,1
34.8
MD,20
VA,23
FL,24
CO,34
MA,49
WA,99
FL,24
MA,49
MD,20
VA,23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment