I executed a query in TDengine.
My SQL statement is :
select count(distinct id_number) from attendance where project_number = "202201130002" and attendance_mark = "1" group by id_number;
It reported an error:
DB error: syntax error near "distinct id_number) from attendance where project_number = "202201130002" and attendance_mark = "1" group by id_number;" (0.000143s)
Is there any syntax error in this sentence? How should I write it?
Related
I am struggling because the code i have done is not working
I always get an error with my syntax :
"Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT SUM(order_amount) as gms, SUM(order_amount*fees_percentage) as ar, SUM(' at line 2"
This is my code:
WITH totals AS(
SELECT SUM(order_amount) as gms,
SUM(order_amount*fees_percentage) as ar,
SUM(order_amount*(fees_percentage - payment_cost_percentage) as gm,
FROM data
WHERE has_discount > 0
SELECT
gms/SUM(order_amount) AS GMS,
ar/SUM(order_amount*fees_percentage) AS ar,
gm/SUM(order_amount*(fees_percentage - payment_cost_percentage) AS gm,
FROM data
LEFT JOIN totals ON data.retailer_id = totals.retailer_id)))
I tried many things but nothing is working, someone can explain me ?
Thank you
Update : I corrected it :
WITH totals AS(
SELECT SUM(order_amount) AS gms,
SUM(order_amount*fees_percentage) AS ar,
SUM(order_amount*(fees_percentage - payment_cost_percentage)) AS gm
FROM data
WHERE has_discount > 0)
SELECT
gms/SUM(order_amount) AS GMS,
ar/SUM(order_amount*fees_percentage) AS ar,
gm/SUM(order_amount*(fees_percentage - payment_cost_percentage)) AS gm
FROM data
LEFT JOIN totals ON data.retailer_id = totals.fees_percentage
But now i have an issue with this error :
Error Code: 1054. Unknown column 'totals.fees_percentage' in 'on clause'
i don't know how to figure it out
I am running below query in Snowflake:
UPDATE PROVIDER_XO_SCORE_TABLE AS PXS
SET PXS.PROVIDER_ID = (SELECT P.PROVIDER_ID
FROM PROVIDER_TABLE P
WHERE PXS.XPI = P.XPI);
This query working fine in MySql but giving below error message in Snowflake.
SQL compilation error:
Unsupported subquery type cannot be evaluated
You can use the join-like syntax with UPDATE...FROM:
UPDATE PROVIDER_XO_SCORE_TABLE PXS
SET PROVIDER_ID = P.PROVIDER_ID
FROM PROVIDER_TABLE P
WHERE PXS.XPI = P.XPI;
I am sure that you are used to this question but nonetheless I am having trouble with my SQL script. It is very frustrating.
When I execute the SQL against the SAP Hana database, I continuously receive this error:
Errors occurred while executing the SQL statement: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near ")": line 14 col 35
Let me present the SQL concerned here:
SELECT
BKPF.BKTXT, BKPF.MONAT, BSEG.BELNR, BSEG.BUKRS, BSEG.DMBTR, BSEG.GJAHR, BSEG.MANDT, BSEG.PRCTR, BSEG.SAKNR, CEPCT.KTEXT, CEPCT.LTEXT, SKAT.MCOD1, SKAT.TXT20, SKAT.TXT50
FROM
SAPPR1.BSEG
INNER JOIN SAPPR1.BKPF ON BSEG.GJAHR = BKPF.GJAHR
INNER JOIN SAPPR1.CEPCT ON BSEG.PRCTR = CEPCT.PRCTR
INNER JOIN (SELECT
SAKNR, TXT20, TXT50, MCOD1
FROM
SAPPR1.SKAT
WHERE
SPRAS not LIKE '%[a-z0-9 .]%' ) AS SKAT_SUB ON BSEG.SAKNR = SKAT_SUB.SAKNR
WHERE
BKPF.MONAT = (SELECT Month('?')-1)
AND (BSEG.GJAHR = (SELECT Year('?')-1 HAVING Month('?')-1 < 4) OR BSEG.GJAHR = (SELECT Year('?') HAVING Month('?')-1 > 3))
AND BSEG.MANDT = ?
;
Unlike other DBMS HANA does not support selecting records out of nothing.
A SELECT without a FROM is not valid.
In order to create a single-row set one can use the DUMMY table.
SELECT current_date FROM DUMMY;
creates the single-row set with the result of the function expression.
Having said that, for comparisons a set is not required. Instead the function can be directly put into the expression:
WHERE
BKPF.MONAT = (MONTH(?)-1)
Also note that for string typed bind variables no quotation marks are required or allowed.
When I try to import teradata data with a where in the sql statement I get the following error
clients<-dbGetQuery(con, "SELECT * from clients where year(cl_dataentrada) = 2018")
Error in new_result(connection#ptr, statement) :
nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword.
clients<-data.frame(clients)
I've also tried:
clients<- dbSendQuery(con, "SELECT * from clients where year(cl_dataentrada) = 2018")
Error in new_result(connection#ptr, statement) :
nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword.
Also in a sql chunk :
SELECT * from clients where year(cl_dataentrada) = 2018
Error in new_result(connection#ptr, statement) :
nanodbc/nanodbc.cpp:1344: 42000: [Teradata][ODBC Teradata Driver]Teradata DatabaseSyntax error: expected something between the 'where' keyword and the 'year' keyword.
Failed to execute SQL chunk
As Shiva Prakash suggested this finally works:
clients<-dbGetQuery(con, "SELECT * from clients where extract(year from cl_dataentrada)=2018")
It was an error because the function year is an odbc function not Teradata.
Thank you.
Hello guys I am running this query to get some data from database table.
select pickup, supplier, sum(price)
from myrent_prices_to
where (pickup BETWEEN '2018-01-01' and '2018-07-31')
and location SIMILAR TO '(%)'
and vehicleclass SIMILAR TO '(%)'
and supplier SIMILAR TO '(%)'
group by pickup, supplier
But it is giving me error below:
org.eclipse.birt.report.engine.api.EngineException: Error happened
while running the report. at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.doRun(DatasetPreviewTask.java:135)
at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.runDataset(DatasetPreviewTask.java:97)
at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.execute(DatasetPreviewTask.java:49)
at
org.eclipse.birt.report.designer.data.ui.dataset.DataSetPreviewer.preview(DataSetPreviewer.java:69)
at
org.eclipse.birt.report.designer.data.ui.dataset.ResultSetPreviewPage$5.run(ResultSetPreviewPage.java:336)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.birt.data.engine.odaconsumer.OdaDataException:
Cannot get the result set metadata.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object. SQL error #1:ERROR: syntax error
at or near "group" Position: 236 ;
org.postgresql.util.PSQLException: ERROR: syntax error at or near "group" Position: 236 at