I have an interview coming up in which I will write code in Coderpad. What is the syntax to write SQL in Coderpad? (note Coderpad with an "r", not Codepad).
First, you select a language for Coderpad. I am selecting Scala.
Here is a database they provide:
+--------------------+-----------+---------------+
| Table Name | Row Count | Table Size KB |
+--------------------+-----------+---------------+
| departments | 5 | 16.0000 |
| employees | 6 | 32.0000 |
| employees_projects | 5 | 48.0000 |
| projects | 3 | 16.0000 |
+--------------------+-----------+---------------+
Here is Scala code that does work:
object Solution extends App {
for (i <- 0 until 5) println("Hello, World!")
}
I want to run a simple SQL query.
SELECT * FROM employees;
Note: I can write complex SQL in Spark with Scala. I have written hundreds of Databricks Scala notebooks. So, I do not need a primer on Scala or SQL.
I simply need the correct SYNTAX to write any simple SQL query in CoderPad just to get me started. Thank you.
In other words, how do I insert a SQL statement into a Scala Object?
I tried:
object Solution extends App {
//for (i <- 0 until 5) println("Hello, World!")
val myTest = SQL("select * from employees").as(mapping *)
myTest.take(1)
}
But get this error:
Solution.scala:6: error: not found: value SQL
val myTest = SQL("select * from employees").as(mapping *)
^
Solution.scala:6: error: not found: value mapping
val myTest = SQL("select * from employees").as(mapping *)
Copyright Notice:Content Author:「user3439308」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48242035/writing-sql-in-coderpad