You can pass a string into sql statement like below
id = "1"query = "SELECT count from mytable WHERE id='{}'".format(id)sqlContext.sql(query)
You are almost there just missed s :)
s
sqlContext.sql(s"SELECT count from mytable WHERE id=$id")
Since the accepted answer didn't work for me, I am writing my own answer using string interpolation.
sqlContext.sql(s"""SELECT count from mytable WHERE id='${id}'""")