一句sql可以搞定$sql = "select addtime,id,ip,sum(ip) as sip from table group by id"
Sorry 更正得使用零时表 create temporary table tmp_table as select price from table group by priceselect addtime,id,ip,sum(ip) as sip from table group by id having price in (select princ from tmp_table)
相加是要看单价,各ID相同时在相加
当单价不同,ID相同时,只把相同单价的数据相加,不同的列出来就行。
就上我上面的报表图列一样的当 100012 有3天 单价为 32 而结算规则为IP 那么就把那三天的IP相加
当100012 有5天单价为 33 而结算规则为IP 那么就把那5天的IP相加
create temporary table tmp_table as select price from table group by priceselect addtime,id,ip,sum(ip) as sip from table group by id having price in (select princ from tmp_table)