在mysql中声明一个具有多个连接表的变量

i2loujxw  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(422)

我试图得到mysql workbench中需要多个表连接的id创建的最初月份的结果列。

SET @in_month = '0';

SELECT 
    ca.id
FROM capital.user ca
    JOIN 
    capital.user_account cd on ca.id = cd.user_id
    JOIN
    capital.transaction ct on cd.user_id = ct.user_account_id
    JOIN
    capital.transaction_event ce on ct.id = ce.auth_entry_id 

  @in_month = month(ce.created) WHERE ce.message = 'Approved'

Group by id;

我得到语法错误:“@in_month”(在文本后缀处)在第17行的这个位置不是有效的输入,你知道我可能做错了什么吗?我对sql没有太多经验

nwlls2ji

nwlls2ji1#

变量声明后缺少分号&在连接条件下缺少分号

SET @in_month = '0';

    SELECT 
        ca.id
    FROM capital.user ca
    JOIN capital.user_account cd on ca.id = cd.user_id
    JOIN capital.transaction ct on cd.user_id = ct.user_account_id
    JOIN capital.transaction_event ce on ct.id = ce.auth_entry_id  and 
         @in_month = month(ce.created) 
    WHERE ce.message = 'Approved'
    Group by id;

相关问题