MySQL [Error] 1064

时间:2017-06-15 09:45:46

标签: mysql explain navicat

I got this MySQL error 1064 when I ran the EXPLAIN on VIEWS table in Navicat and could not figure out where exactly the error from in this brief code:

SET @runningbal = 0;
SELECT
cashinflow_v.TxnDate,
cashinflow_v.TxnType,
cashinflow_v.Amount,    
@runningbal := @runningbal + cashinflow_v.Amount as Balance
FROM
cashinflow_v
ORDER BY cashinflow_v.TxnDate

The error says:

[SQL] EXPLAIN SET @runningbal = 0;
SELECT
cashinflow_v.TxnDate,
cashinflow_v.TxnType,
cashinflow_v.Amount,
@runningbal := @runningbal + cashinflow_v.Amount as Balance
FROM
cashinflow_v
ORDER BY cashinflow_v.TxnDate

[Err] 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 'SET 
@runningbal = 0;
SELECT
cashinflow_v.TxnDate,
cashinflow_v.TxnType,
cash' at line 1

I will appreciate if anyone could help me with this. Thanks!

2 个答案:

答案 0 :(得分:0)

Change:

from:

EXPLAIN SET @runningbal = 0;

to

 SET @runningbal = 0;

答案 1 :(得分:0)

The EXPLAIN statement expects either a table name or a query of one of these types:

  • SELECT
  • DELETE
  • INSERT
  • REPLACE
  • UPDATE

It's just not designed to provide information of arbitrary SQL commands (how could it?).

If it's your SQL client the one that's trying to explain the query, you may need to instruct it to handle the code block as script rather than individual statement.