mysql - How to set a value to subquery select case variables -
how pre-assign value row_num , accid in below query in mysql. please help!!!!!!!!!!!
part of stored procedure,
i had declare variable , assigned values as,
declare row_num int; declare accid int; set row_num:=1; set accid:=1;
the above assigned values not set in below query. goes else part , returning 1 rows.
insert test1 (accountid,claum,opaum,valuationdate,rownumber) select accountid, claum, 0, valuationdate, rownumber (select accountid, valuationdate, claum, @row_num:=(case when @accid= accountid @row_num+1 else 1 end) rownumber, @accid:=accountid acc (select accountid, valuationdate, sum(aum) claum tempaum group accountid, valuationdate order accountid, valuationdate) ) claum;
you can set values using subquery. in addition, should variable assignments in single statement. mysql not guarantee order of evaluation of statements in select
statement. so:
insert test1(accountid, claum, opaum, valuationdate, rownumber) select accountid, claum, 0, valuationdate, rownumber (select accountid, valuationdate, claum, (@row_num := (case when @accid = accountid @row_num + 1 when @accid := accountid 1 else 1 end) ) rownumber (select accountid, valuationdate, sum(aum) claum tempaum group accountid, valuationdate ) cross join (select @row_num := 0, @accid := null) params order accountid, valuationdate ) claum;
Comments
Post a Comment