MySQL user-defined variable in WHERE clause

前端 未结 4 1279
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 19:20

I want to know if there is a way to use a user-defined variable in WHERE clause, as in this example:

SELECT id, location, @id := 10 FROM songs W         


        
4条回答
  •  清酒与你
    2020-12-18 19:52

    Not far from what Mike E. proposed, but one statement:

    SELECT id, location FROM songs, ( SELECT @id := 10 ) AS var WHERE id = @id;
    

    I used similar queries to emulate window functions in MySQL. E.g. Row sampling - just an example of using variables in the same statement

提交回复
热议问题