您的当前位置:首页正文

mysql 统计sql语句_mysql 中关于统计的SQL语句怎么写

2024-11-07 来源:个人技术集锦

首先要确定你重复的记录最多有多少条,我这里假设最多有两条重复customerid的记录

select

customerId,

case when count(*)>=2 then 2 else max(type) end as type,

sum(orderNum) as orderNum,

SUBSTRING_INDEX(group_concat(shkd),',',1) as shkd,

SUBSTRING_INDEX(group_concat(srmb),',',1) as srmb,

SUBSTRING_INDEX(group_concat(ahkd),',',1) as ahkd,

SUBSTRING_INDEX(group_concat(armb),',',1) as armb,

SUBSTRING_INDEX(group_concat(shkd),',',-1) as shkd2,

SUBSTRING_INDEX(group_concat(srmb),',',-1) as srmb2,

SUBSTRING_INDEX(group_concat(ahkd),',',-1) as ahkd2,

SUBSTRING_INDEX(group_concat(armb),',',-1) as armb2

from tableName group by customerId

Top