使用SET编写正确的MySQL查询

使用SET编写正确的MySQL查询,mysql,Mysql,我有以下疑问: select count(*) from @table := ( select table_name from information_schema.TABLES where table_schema = 'sbnp_phalanx_queue' order by CREATE_TIME desc limit 1 ) where mtime < DATE_SUB(Now(), INTERVAL 3 DAY); 但我有一个错误: 错误

我有以下疑问:

select count(*)
from @table := (
    select table_name
    from information_schema.TABLES
    where table_schema = 'sbnp_phalanx_queue'
    order by CREATE_TIME desc
    limit 1
)
where mtime < DATE_SUB(Now(), INTERVAL 3 DAY);
但我有一个错误:

错误1064 42000:您的SQL语法有错误;检查 与右边的MySQL服务器版本相对应的手册 在“@table=select table\u name from”附近使用的语法 信息\u schema.TABLES,其中第1行的表\u schema='


如何正确执行?

查询中不能使用表名表达式。必须使用存储过程中的“准备并执行”来执行。这太糟糕了。我必须在一行中执行它对不起,MySQL不是这样工作的。我不理解你的子查询。您正在匹配一个精确的表名,那么为什么不能直接从主查询中的sbnp_phalanx_队列写入?为什么需要ORDER BY和LIMIT,只有一个表具有该名称。