方法一: 直接写入数据库:update 表 set 合计字段名称=累加字段1+累加字段2 方法二: 读取时计算(效率不高):select *,(累加字段1+累加字段2) as 合计字段名称 from 表
排名 用触发器: /* ****xx排名**** */ select @M_max=max(CHI) from PTGK_LK select @M_count=count(*)from PTGK_LK where CHI <>0 set @m_cs=@M_count Set @m_pm=1 while @m_cs >0 begin select @n_max=max(CHI) from PTGK_LK where CHI<@M_maxif @M_max<>0 begin update PTGK_LK set CHIP=@m_pm where CHI=@M_max endselect @count=count(*) from PTGK_LK where CHI=@M_max set @M_max=@n_max set @m_pm=@m_pm+@count set @m_cs=@m_cs-1 end
直接写入数据库:update 表 set 合计字段名称=累加字段1+累加字段2
方法二:
读取时计算(效率不高):select *,(累加字段1+累加字段2) as 合计字段名称 from 表
/* ****xx排名**** */
select @M_max=max(CHI) from PTGK_LK
select @M_count=count(*)from PTGK_LK where CHI <>0
set @m_cs=@M_count
Set @m_pm=1
while @m_cs >0
begin
select @n_max=max(CHI) from PTGK_LK where CHI<@M_maxif @M_max<>0
begin
update PTGK_LK set CHIP=@m_pm where CHI=@M_max
endselect @count=count(*) from PTGK_LK where CHI=@M_max
set @M_max=@n_max
set @m_pm=@m_pm+@count
set @m_cs=@m_cs-1
end