Nested select statements in impala sql - sql

I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!

#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';

Related

Error making a selection in Teradata with R

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.

Impala query: Exception: Syntax error caused by cast function

I have the following Impala query
select session_id, max(cast(milli_ts) as integer), min(cast(milli_ts) as integer)from my_table group by session_id
But got the following errors:
HiveServer2Error: AnalysisException: Syntax error in line 10:
...sion_id, max(cast(milli_ts) as integer), min(cast(mill...
^
Encountered: )
Expected: AND, AS, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, NOT, OR, REGEXP, RLIKE
CAUSED BY: Exception: Syntax error
Any idea what I missed? Thanks!
The correct syntax for CAST is as following:
cast(milli_ts as integer)

Syntax Error In Query with selectRaw and time diff

please advice how to correct this query
$no_of_hours = DB::Table('shifts')
->where('time_sheet_id','=', $timesheet_id->id)
->selectRaw("SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
->get();
return $no_of_hours;
im getting following error
SQLSTATE[42000]: Syntax error or access violation: 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 time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts`' at line 1 (SQL: select SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts` where `time_sheet_id` = 35)
You have a sintax error probably because you don't have to write the SELECT keyword in the selectRaw function ( the keyword is added implicity by the query builder in this case ):
->selectRaw("time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")

PreparedStatementCallback; bad SQL grammar

I'm getting the following sql error in my sql command! please can anyone explain me what I'm doing wrong here!
15:20:43,686 ERROR [PageExceptionFlowInterceptor] Exception (EJBException) while executing Action [com.jkcs.khms.web.cashiering.hotelTax.HotelTaxAction] : org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT * FROM (SELECT rs_qry.*, ROWNUM rn_qry FROM ( SELECT ht.htl_tax_id,
ht.hotel_id,
ht.tax_id,
ht.status,
ht.display_sequence,
t.id,
t.code,
h.hotel_name,
h.hotel_id
FROM
PMS_T_HTL_TAX ht,
CRS_T_TAX t,
CRS_T_HOTEL h WHERE ht.hotel_id IN (1) AND ht.tax_id IN (31,3,37,38,36,23,29,30,24,10,12,20,11,1,16,17,18,19,34,35,15,33,22,2,21,32) order by ht.hotel_id, ht.htl_tax_id ) rs_qry ) WHERE rn_qry BETWEEN 1 AND 10]; nested exception is java.sql.SQLException: ORA-00904: "T"."ID": invalid identifier
Your CRS_T_TAX table doesn't have a column called ID

Advantage Database 8.1 SQL IN clause

Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )