mysql 老人类型逗号隔开多个,类型分类统计数量,分组排序

该SQL查询从kn_customer_information表中提取以逗号分隔的customer_type_name,通过连接help_topic表并利用substring_index函数进行拆分,统计各类型数量,按数量降序排列。查询条件包括未删除、已审计状态以及可能的部门过滤。
摘要由CSDN通过智能技术生成
老人类型逗号隔开多个,类型分类统计数量,分组排序
SELECT
            b.customer_type_name AS itemName,
            count( customer_type_name ) AS
            VALUE
            FROM
            (
            SELECT
            customer_information_id,
            substring_index( substring_index( a.customer_type_name, ',', b.help_topic_id + 1 ), ',',- 1 ) AS customer_type_name
            FROM
            kn_customer_information a
            JOIN mysql.help_topic b ON b.help_topic_id <![CDATA[<]]> ( length( a.customer_type_name ) - length( REPLACE ( a.customer_type_name, ',', '' ) ) + 1 )
            WHERE
            a.is_deleted = 0
            AND a.audit_status = 2
            <if test="deptIds != null and deptIds.size() > 0">
                AND a.create_dept in
                <foreach collection="deptIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            ) b
            GROUP BY
            b.customer_type_name
            ORDER BY
            count( customer_type_name ) DESC
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值