需要按時(shí)間分組統(tǒng)計(jì)分組后的price總和 number總合 并要取出分組中的第一個(gè)price和最后一個(gè)price的值找了好久找不到相應(yīng)的方法希望各位能指導(dǎo)一下
2 回答

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
時(shí)間分組,排序字段不清,姑且按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貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
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 關(guān)注
- 2981 瀏覽
添加回答
舉報(bào)
0/150
提交
取消