How to store Query Result in variable using mysql

后端 未结 4 1561
南旧
南旧 2020-12-04 08:28
SET @v1 := SELECT COUNT(*) FROM user_rating;
SELECT @v1

When I execute this query with set variable this error is shown.



        
相关标签:
4条回答
  • 2020-12-04 08:33

    Additionally, if you want to set multiple variables at once by one query, you can use the other syntax for setting variables which goes like this: SELECT @varname:=value.

    A practical example:

    SELECT @total_count:=COUNT(*), @total_price:=SUM(quantity*price) FROM items ...
    
    0 讨论(0)
  • 2020-12-04 08:33

    use this

     SELECT weight INTO @x FROM p_status where tcount=['value'] LIMIT 1;
    

    tested and workes fine...

    0 讨论(0)
  • 2020-12-04 08:34
    Select count(*) from table_name into @var1; 
    Select @var1;
    
    0 讨论(0)
  • 2020-12-04 08:40

    Surround that select with parentheses.

    SET @v1 := (SELECT COUNT(*) FROM user_rating);
    SELECT @v1;
    
    0 讨论(0)
提交回复
热议问题