其他
mySQL 中分组函数的写法
--max最大值所有行
select it.user_id,
it.income,
case
when @maxVal is not null then @maxVal := @maxVal
when @maxVal is null then @maxVal := it.income
end AS sum_income
from income_tl it, (select @maxVal:=null) r
order by it.income
select it.user_id,
it.income,
@maxVal := IFNULL(@maxVal,it.income)
from income_tl it, (select @maxVal:=null) r
order by it.income
--max最大值,分组行
select it.user_id,
it.income,
case
when @preVal = it.user_id then @maxVal := @maxVal
when @preVal := it.user_id then @maxVal := it.income
end AS sum_income
from income_tl it, (select @preVal:=null, @maxVal:=null) r
order by it.user_id asc, it.income asc;
长按二维码关注公众号