Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find SQL syntax error [closed]

Tags:

sql

mysql

i am trying to run this SQL Query:

SELECT avg(response_seconds) as s FROM 
    ( select time_to_sec( timediff( from_unixtime( floor( UNIX_TIMESTAMP(u.datetime)/60 )*60 ), u.datetime) ) ) as response_seconds 
    FROM tickets t JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber 
    WHERE u.type = 'update' and t.customer = 'Y' and DATE(u.datetime) = '2016-04-18' 
    GROUP BY t.ticketnumber) 
    AS r 

but i am seeing this error:

#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 'FROM tickets t JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber WHE' at line 3

and i cannot work out where the error is in the query

like image 334
charlie Avatar asked Apr 20 '26 09:04

charlie


1 Answers

Remove the ) just before as response_seconds

SELECT avg(response_seconds) as s FROM 
    ( select time_to_sec( timediff( from_unixtime( floor( UNIX_TIMESTAMP(u.datetime)/60 )*60 ), u.datetime) ) as response_seconds 
      FROM tickets t 
         JOIN ticket_updates u ON t.ticketnumber = u.ticketnumber 
      WHERE u.type = 'update' 
        and t.customer = 'Y' 
        and DATE(u.datetime) = '2016-04-18' 
      GROUP BY t.ticketnumber
    ) AS r 

You had to many closing brackets on that calculation which had the effect of closing the sub select to early.

like image 182
RiggsFolly Avatar answered Apr 22 '26 22:04

RiggsFolly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!