I am running a process on Spark which uses SQL for the most part. In one of the workflows I am getting the following error:
mismatched input 'GROUP' expecting
spark.sql("SELECT state, AVG(gestation_weeks) "
"FROM natality "
"WHERE state is not null "
"HAVING AVG(gestation_weeks) > (SELECT AVG(gestation_weeks) FROM natality) "
"GROUP BY state").show()
I cannot figure out what the error is for the life of me
I've tried checking for comma errors or unexpected brackets but that doesn't seem to be the issue
The SQL constructs should appear in the following order:
SELECT
FROM
WHERE
GROUP BY **
HAVING **
ORDER BY
Related
I'm trying to merge the first name and surname columns of this table into a new column but I'm not getting it to work. I've tried a few variations but I get very similar errors. What am I doing wrong?
SELECT *,
CONCAT(full_dataset.First_name, " ", full_dataset.Surname) AS Full_name
FROM full_dataset
gives me
ERROR: column full_dataset.first_name does not exist
LINE 2: CONCAT(full_dataset.First_name, " ", full_dataset.Surname) A...
^
HINT: Perhaps you meant to reference the column "full_dataset.First_name".
SQL state: 42703
Character: 18
whilst
SELECT *,
CONCAT("full_dataset.First_name", " ", "full_dataset.Surname") AS Full_name
FROM full_dataset
gives me
ERROR: column "full_dataset.First_name" does not exist
LINE 2: CONCAT("full_dataset.First_name", " ", "full_dataset.Surname...
^
SQL state: 42703
Character: 18
I've also tried ("First_name", " ", "Surname") amongst other variants
This is a section of my table (edited to remove private info)
Thank you very much for any help, I appreciate it.
Don't Use "" Double Quote inside Concat Function Used ' Single Quote
Try Following
SELECT *,
CONCAT(full_dataset.First_name, ' ' , full_dataset.First_name) AS Full_name
FROM full_dataset
this my SQL query
"SELECT doctor.id,users.first_name,users.last_name,users.email,users.password, users.birthday,users.address,users.phone,users.role_id,doctor.id_type,specialty.name, count(patient.id)as count_patient"
+ "FROM patient RIGHT JOIN users INNER JOIN doctor ON users.id=doctor.id "
+ "INNER JOIN specialty ON specialty.id=doctor.id_type ON doctor.id =patient.id_doctor)"
+ "GROUP BY doctor.id,users.first_name,users.last_name,users.email,users.password,users.birthday,users.address,users.phone,users.role_id,doctor.id_type,specialty.name ORDER BY users.first_name";
I have error on eclepse
[ERROR] DoctorDAO(sortByFirstName):185 - Syntax error: Encountered "patient" at line 1, column 204.
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "patient" at line 1, column 204.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)....
I know that the table was set and the 'SQL' query is executed in the IJ console derby.
Looks like you're missing a space in the statement: count_patient" + "FROM Failing that, I'd suggest printing the string and pasting that into your question.
Tried to search for an answer using "SQLDF append in code", but I couldnt find any answer.
Basically, I'd like to be able to write something like that :
divisor<-4
result<-sqldf("SELECT id, some_number/ " . divisor . " FROM my_table")
but I can't find a way to have divisor included in the SQL statement : Error: unexpected symbol in "result<-sqldf("SELECT id, some_number/ " ."
I tried having &, + and nothing instead of the dots ., but I can't find anything that works.
I also tried "SELECT id, some_number/divisor FROM my_table", without any " " around divisor, but I get error in statement: no such column: divisor
Thanks.
You can use
result<-sqldf(sprintf("SELECT id, some_number/%d FROM my_table", divisor))
Hope this helps
I'm trying to execute below query but error occur like
Syntax error (missing operator) in query expression 9 ORDER BY empSalary.ID DESC.
cmd.CommandText = "UPDATE EmpSalary SET emp_Advance=" & TextBox7.Text & ",emp_salary=" & TextBox4.Text & " ORDER BY empSalary.ID DESC"
First, you should never concatenate strings directly to your sql. This is a security risk. Google sql injection.
Instead, you should use parameterized queries or stored procedures.
Second, the oreder by part has no meaning in this type of query, and perhaps is the reason you get this exception.
I keep getting an error every time i run this code saying Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier. And I don't know what to do. Someone please help
tc = dt1.Compute("Sum(Calories Burned)", "[Runner Name] = '" & Label1.Text & "'")