我有一个包含复杂连接的查询。如果结果不为空,则类似于连接多个子选择的结果。它在我们运行 MySQL 5.1 的开发服务器上运行良好(尽管复杂性让我有点恶心),但在我们运行 5.0 报告的生产服务器上运行良好
FUNCTION database.concat does not exist
任何想法为什么会这样?不幸的是,此时升级不是一种选择,所以除非有人有一个好主意,否则我几乎无法重写这份报告。
查询如下(是的,我意识到我在严重滥用 mysql。让我们暂时搁置它。如果有人知道如何通过别名引用子选择会很方便,但我从来没有能够做到它,因此是重复的子选择。NULL
如果任何参数是,则concat 也会返回NULL
,因此是 if 语句。)
select (concat(if((select
concat(if(b.foo is not null, b.foo, ""),
" ",
if(f.bar is not null, f.bar, ""))
from `foo_table` as f
left join `bar_table` as b
on b.SOME_ID = f.SOME_ID
where f.STUDENT_ID = t.STUDENT_ID
and bar.NewID = t.OldID order by bar.id limit 1) is not null,
(select
concat(if(b.foo is not null, b.foo, ""),
" ",
if(f.bar is not null, f.bar, ""))
from `foo_table` as f
left join `bar_table` as b
on b.SOME_ID = f.SOME_ID
where f.STUDENT_ID = t.STUDENT_ID
and bar.NewID = t.OldID order by bar.id limit 1),
""),
" ",
t.reason) as Reason
from table as t