您打开1
(并关闭2
)。删除最后一个:
SELECt CONCAt('changes',year,month) FROM changes编辑
第二个语句应该是
SET @x := SELECt * FROM (@b) as b;
那行得通,但是不确定那是否是您想要的:
SET @b := 'SELECt CONCAt(''changes'',`year`,`month`) FROM whichchanges';SET @x := 'SELECt * FROM (SELECt CONCAt(''changes'',`year`,`month`) FROM whichchanges) as b';Prepare stmt FROM @b;Prepare stmt FROM @x;Execute stmt;编辑2
如果我理解正确,那么您正在寻找一个查询:
select * from changeswhere change_column in (select distinct concat(`year`, `month`) from whichchanges)
编辑3
select @b := group_concat(concat(' select * from changes', `year`, `month`, ' union ') separator ' ') as w from whichchanges;set @b := left(@b, length(@b) - 6);Prepare stmt FROM @b;Execute stmt;SQLFiddle示例



