How to declare a variable in MySQL?

后端 未结 7 1587
春和景丽
春和景丽 2020-11-22 05:01

How to declare a variable in mysql, so that my second query can use it?

I would like to write something like:

SET start = 1;
SET finish = 10;

SELECT         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 05:40

    For any person using @variable in concat_ws function to get concatenated values, don't forget to reinitialize it with empty value. Otherwise it can use old value for same session.

    Set @Ids = '';
    
    select 
      @Ids := concat_ws(',',@Ids,tbl.Id),
      tbl.Col1,
      ...
    from mytable tbl;
    

提交回复
热议问题