SQLite - problem with "near « ) » : syntax error" - sql

I try here since i didn't find anything anywhere else.
I have a query which has been check by my colleagues and "teachers", but the error remains:
" near « ) » : syntax error".
The (last) query is the following one:
WITH valeur_par_ville AS
(
SELECT dep_code, com_code, AVG(valeur_fonciere) as valeur
FROM vente
JOIN bien ON bien.bien_id = vente.bien_id
JOIN commune ON commune.com_id = bien.com_id
WHERE dep_code IN (6,13,33,59,69)
GROUP BY dep_code, com_id
)
SELECT dep_code AS "Département", com_id AS "Commune", round(valeur,1) AS "Prix moyen"
FROM(
SELECT dep_code, com_nom, valeur_fonciere,
rank() OVER (PARTITION BY dep_code ORDER BY valeur_fonciere DESC) AS
rang
FROM valeur_par_ville) AS result
WHERE rang <= 3
I hope you can help me on this, because it becomes "black magic" to me!
Thanks.
I tried different ways to reach a result, but the same thing keeps going... I Checked all my data tables, updated SQLite (so PARTITION BY works on it now), reboot, checked the query little by little... No idea where it comes from.
Others colleagues (we are kind of students) managed to have a valid result with their own queries.
But for me:
" near « ) » : syntax error".

The error is coming from a different part of the code. I added CREATE TABLE statements to be able to run your code and it's failing differently.
CREATE TABLE vente(dep_code, com_code, valeur_fonciere, bien_id);
CREATE TABLE bien(bien_id, com_id);
CREATE TABLE commune(com_id);
-- your code here
The error:
Parse error near line 4: ambiguous column name: com_id
RE dep_code IN (6,13,33,59,69) GROUP BY dep_code, com_id ) SELECT dep_code AS
error here ---^
After prefixing it with a table name, there's another bunch of errors, e.g.
arse error near line 4: no such column: com_nom
(valeur,1) AS "Prix moyen" FROM( SELECT dep_code, com_nom, valeur_fonciere, ra
error here ---^
Parse error near line 4: no such column: valeur_fonciere
) AS "Prix moyen" FROM( SELECT dep_code, com_nom, valeur_fonciere, rank() OVER
error here ---^
etc.

Related

What is the syntax problem here using this subquery inside where clause

SELECT p.pnum, p.pname
FROM professor p, class c
WHERE p.pnum = c.pnum AND c.cnum = CS245 AND (SELECT COUNT(*) FROM (SELECT MAX(m.grade), MAX(m.grade) - MIN(m.grade) AS diff
FROM mark m WHERE m.cnum = c.cnum AND m.term = c.term AND m.section = c.section AND diff <= 20)) = 3
Incorrect syntax near ')'. Expecting AS, FOR_PATH, ID, or QUOTED_ID.
Consider the following example:
SELECT COUNT(1)
FROM SYSCAT.TABLES T
WHERE
(
-- SELECT COUNT(1)
-- FROM
-- (
SELECT COUNT(1)
FROM SYSCAT.COLUMNS C
WHERE C.TABSCHEMA=T.TABSCHEMA AND C.TABNAME=T.TABNAME
-- )
) > 50;
The query above works as is. But the problem is, that if you uncomment the commented out lines, you get the following error message: "T.TABNAME" is an undefined name. and least in Db2 for Linux, Unix and Windows.
You can't push external to the sub-select column references too deeply.
So, your query is incorrect.
It's hard to correct it, until you provide the task description with data sample and the result expected.
I can see a potential syntax errors: It seems that CS245 refers to a value c.cnum may take and not a column name. If that is the case, it should be enclosed in single quotes.

U-sql error: Expected one of: AS EXCEPT FROM GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE ';' ')' ','

I have a following table:
EstimatedCurrentRevenue -- Revenue column value of yesterday
EstimatedPreviousRevenue --- Revenue column value of current day
crmId
OwnerId
PercentageChange.
I am querying two snapshots of the similarly structured data in Azure data lake and trying to query the percentage change in Revenue.
Following is my query i am trying to join on OpportunityId to get the difference between the revenue values:
#opportunityRevenueData = SELECT (((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue)*100)/opty.EstimatedCurrentRevenue) AS PercentageRevenueChange, optyPrevious.EstimatedPreviousRevenue,
opty.EstimatedCurrentRevenue, opty.crmId, opty.OwnerId From #opportunityCurrentData AS opty JOIN #opportunityPreviousData AS optyPrevious on opty.OpportunityId == optyPrevious.OpportunityId;
But i get the following error:
E_CSC_USER_SYNTAXERROR: syntax error. Expected one of: AS EXCEPT FROM
GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE ';' ')'
','
at token 'From', line 40
near the ###:
This expression is having the problem i know but not sure how to fix it.
(((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue)*100)/opty.EstimatedCurrentRevenue)
Please help, i am completely new to U-sql
U-SQL is case-sensitive (as per here) with all SQL reserved words in UPPER CASE. So you should capitalise the FROM and ON keywords in your statement, like this:
#opportunityRevenueData =
SELECT (((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue) * 100) / opty.EstimatedCurrentRevenue) AS PercentageRevenueChange,
optyPrevious.EstimatedPreviousRevenue,
opty.EstimatedCurrentRevenue,
opty.crmId,
opty.OwnerId
FROM #opportunityCurrentData AS opty
JOIN
#opportunityPreviousData AS optyPrevious
ON opty.OpportunityId == optyPrevious.OpportunityId;
Also, if you are completely new to U-SQL, you should consider working through some tutorials to establish the basics of the language, including case-sensitivity. Start at http://usql.io/.
This same crazy sounding error message can occur for (almost?) any USQL syntax error. The answer above was clearly correct for the provided code.
However since many folks will probably get to this page from a search for 'AS EXCEPT FROM GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE', I'd say the best advice to handle these is look closely at the snippet of your code that the error message has marked with '###'.
For example I got to this page upon getting a syntax error for a long query and it turned out I didn't have a casing issue, but just a malformed query with parens around the wrong thing. Once I looked more closely at where in the snippet the ### symbol was, the error became clear.

Query giving error ora-00923 from keyword not found where expected

I am using Oracle 8i. When I tried to run this below script I am getting the error ora-00923 from keyword not found where expected.
Please find the below query which I am using.
select i.siid,
sp.access_point_status,
csp.id_number,
act.entry_time,
act.addnl_info,
row_num() over (partition by i.siid order by act.entry_time desc) act_row
from table_Service_point sp,
table_case_to_service_point csp,
table_case cs,
table_act_entry act,
(select distinct siid,
iopt.installedopts2axspoint
from table_installed_options iopt,
tmp_efms_clarify inp
where iopt.siid = inp.service_instance
and iopt.siid = 'DSL580155-105-1') i
where sp.objid = csp.case2servicepoint
and csp.id_number = cs.id_number
and cs.objid = act.act_entry2case
and sp.objid = i.installedopts2axspoint
Try using row_number() instead of row_num().
Single quotes '' in oracle denote characters, not names.
Replace
iopt.siid='DSL580155-105-1'
with
iopt.siid="DSL580155-105-1"
I do think row_number() is the correct spelling, not row_num(). Google it for more on how it works. And also, just a reminder, is DSL580155-105-1 actually a column?

Active Record query causing SQLException near "," syntax error

I'm trying to display all such rows of a table STUDENTS which have a value of an attribute, such as COURSE IN a set of given values e.g. 'MS', 'PhD'.
I get the values in the students_controller.rb file using params. I tried to run an Active Record query using where to do the job:
#all_courses = ['MS', 'PhD', 'BA', 'MSc']
#students = Student.where("course IN :courses" , {:courses => params.has_key?(:courses) ? params[:courses].keys : #all_courses})
But I get the following error:
SQLite3::SQLException: near ",": syntax error: SELECT "students".* FROM "students" WHERE (course IN 'MS', 'PhD', 'BA', 'MSc')
I think the error might be due to the absence of ; at the end of the SQL query generated by Active Record, but I cannot do anything to get that semicolon at the end.
You need to use parentheses: "course IN (:courses)"

SQL Error in VBA

I have the following code in SQL (2005) which calculates the avarage user logins on a systm:
with
user_total as
(
select COUNT(distinct ID) as counter
FROM [dbo].[LOG]
where [LOG].DESCRIPTION='Login success.'
AND
Convert(datetime,convert(char(10),[LOG].CREATED_ON,101)) BETWEEN '2009-01- 01' AND '2009-12-31'
),
USER_avg as
(
select counter/365 as Avarage_Daily_Logins
from user_total
)
select *
from USER_avg
Now the problem is when i put this in a VBA macro in excel to get the result in a spcific cell in strSQL = "QUERY SHOWN ABOVE HERE" argument i get the error in excel
incorrect sysntax near the keyword with
Its worth mentioning that i dont break the code in VBA in multiple lines..i have it all in one line.
Use ;WITH ...
WITH usage for a CTE must have ; after the previous statement. To ensure this is the cases, prefix with ;
Check all of your spacings, if there is an error further down the compiler may interpret it as a problem with the with statement.