問題は、select
を混在させることができないことです およびset
1つのステートメントで、構文エラーが発生することは間違いありません:
select*from t where 1 and [email protected]=1;
set
を実行したい場合 select
内 、コロンが等しい
を使用します 構文。これを変更します:
select*from t where 1 and [email protected]=1;
に:
select*,@a:=1 from t where 1;
それぞれに変数を更新する方法は次のとおりです。 行:
create table t(id int); insert t values(1),(2),(3);
[email protected]=0;
[email protected]:=id from t;
また、concat
を実行することもできます :
[email protected]='0';
select @a:=concat(@a,',',id)from t;
またはconcat
先頭の0
なし :
[email protected]='';
select @a:=concat(@a,if(@a='','',','),id)from t;
ただし、マニュアルは明示的に これは危険であると述べています:
これについても言及されています
最後に、風変わりなをしている場合 変数に異なる値型を割り当てるなど、チェックアウトマニュアル 複雑なメカニズムを確実に理解するために。