sql执行报错

Blade 未结 2 991
wangjie
wangjie 剑圣 2022-06-24 17:37

一、该问题的重现步骤是什么?

1. image.png

2. 

3.


二、你期待的结果是什么?实际看到的又是什么?

能够正常执行,我看mysql语句可以在navicat执行返回结果

三、你正在使用的是什么产品,什么版本?在什么操作系统上?


四、请提供详细的错误堆栈信息,这很重要。

Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: select

        CASE WHEN a.base_type=0 THEN 1 ELSE 2 END as type,

        b.customer,

        DATE_FORMAT(b.explosion_date,'%Y-%m-%d') as checkDate,

        count(b.explosion_date) as totalNum,

        sum(a.state != 0) as exceptionNum

        from blast_detonator a

        left join blast_task b

        on a.task_id = b.id

        where a.base_type is not null

         

            AND explosion_date >= ?

         

         

            AND ? > explosion_date

         

        GROUP BY a.base_type,b.customer,checkDate

        ORDER BY checkDate asc

at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:39)

at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.parserSingle(JsqlParserSupport.java:52)

at com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor.beforeQuery(TenantLineInnerInterceptor.java:70)

at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78)

at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)

at com.sun.proxy.$Proxy323.query(Unknown Source)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)

... 125 common frames omitted

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "("

    at line 6, column 12.


Was expecting one of:


    "&"

    ","

    "::"

    ";"

    "<<"

    ">>"

    "ACTION"

    "ANY"

    "AS"

    "BYTE"

    "CASCADE"

    "CAST"

    "CHANGE"

    "CHAR"

    "CHARACTER"

    "COLLATE"

    "COLUMN"

    "COLUMNS"

    "COMMENT"

    "COMMIT"

    "CONNECT"

    "CYCLE"

    "DESC"

    "DESCRIBE"

    "DISABLE"

    "DIV"

    "DO"

    "DUPLICATE"

    "ENABLE"

    "END"

    "EXCEPT"

    "EXCLUDE"

    "EXTRACT"

    "FALSE"

    "FIRST"

    "FN"

    "FOLLOWING"

    "FOR"

    "FORMAT"

    "FROM"

    "GROUP"

    "HAVING"

    "INDEX"

    "INSERT"

    "INTERSECT"

    "INTERVAL"

    "INTO"

    "ISNULL"

    "KEY"

    "LAST"

    "MATERIALIZED"

    "MINUS"

    "NEXTVAL"

    "NO"

    "NOLOCK"

    "NULLS"

    "OF"

    "OPEN"

    "ORDER"

    "OVER"

    "PARTITION"

    "PATH"

    "PERCENT"

    "PRECISION"

    "PRIMARY"

    "PRIOR"

    "RANGE"

    "READ"

    "REPLACE"

    "ROW"

    "ROWS"

    "SCHEMA"

    "SEPARATOR"

    "SEQUENCE"

    "SESSION"

    "SIBLINGS"

    "SIZE"

    "START"

    "TABLE"

    "TEMP"

    "TEMPORARY"

    "TO"

    "TOP"

    "TRUE"

    "TRUNCATE"

    "TYPE"

    "UNION"

    "UNSIGNED"

    "VALIDATE"

    "VALUE"

    "VALUES"

    "VIEW"

    "WHERE"

    "WINDOW"

    "XML"

    "ZONE"

    "["

    "^"

    "|"

    <EOF>

    <K_DATETIMELITERAL>

    <K_DATE_LITERAL>

    <S_CHAR_LITERAL>

    <S_IDENTIFIER>

    <S_QUOTED_IDENTIFIER>


at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:26538)

at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:26377)

at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:91)

at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:163)

at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:59)

at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:37)

at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.parserSingle(JsqlParserSupport.java:49)

... 130 common frames omitted

五、若有更多详细信息,请在下面提供。

2条回答
  • 2022-06-24 22:30

    java代码、查询sql文本、建表sql提供一下,另外你把as的别名换一下不要用到关键字。如果是关键字,就是mybatis的问题,要换一个

    0 讨论(0)
  • 2022-06-25 18:25

    CASE WHEN a.base_type=0 THEN 1 ELSE 2 END as type,这个别名type换个单词试试

    0 讨论(0)
提交回复