需要按时间分组统计分组后的price总和 number总合 并要取出分组中的第一个price和最后一个price的值找了好久找不到相应的方法希望各位能指导一下
2 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
时间分组,排序字段不清,姑且按price排序吧
select mtime,sum(price),sum(number), substring_index(group_concat(price order by price),',',1) min_price, substring_index(group_concat(price order by price),',',-1) max_pricefrom table group by mtime;
汪汪一只猫
TA贡献1898条经验 获得超8个赞
select min(price) as min_price, max(price) as max_price from (select mtime, code, sum(price) as price, sum(number) as number from table_xx group by mtime order by mtime desc) data
- 2 回答
- 0 关注
- 2918 浏览
添加回答
举报
0/150
提交
取消