[Dameng] Convert different values of the same attribute of SQL into a string

Different values ​​of the same attribute in SQL are converted to one string
Function: wm_concat()
Example:

SELECT dual.hwmc,count(dual.jydbh) zjbgzs ,wm_concat(dual.jyjl) zjjg
        from
            (
                select bdc.hwmc,sh.jydbh,case when sh.jyjl == 1 then '合格' when sh.jyjl == 0 then '不合格' end  jyjl
                from "SZFMIMP"."T_STOCK_IN_CHECK" sh
                inner join  "SZFMIMP"."BASIC_DATA_CARGO" bdc on sh.hwdm = bdc.hwdm
                union all
                select
                bdc.hwmc,qi.ZJBGDBH as jydbh,
                case when INSTRB(qi.zlzbjgpd,'不达标',1,1)>0 then '不合格'
                     when INSTRB(qi.zlzbjgpd,'不达标',1,1)=0 then '合格'
                     end  jyjl
                from "SZFMIMP"."T_QUALITY_INSPECTION" qi
                inner join  "SZFMIMP"."BASIC_DATA_CARGO" bdc on qi.hwbm = bdc.hwdm
            ) DUAL
        group by dual.hwmc
        order by count(dual.jydbh) desc

Execution result:
insert image description here
It can be seen that this function converts all values ​​that meet the conditions into a string.
In layman's terms: There are multiple students with the same name in a class. When displaying, you don't want each student to display a piece of data. At this time, you can use this function to let all students with the same name be displayed together to form a string and return. (For specific use, please use it reasonably according to your own business understanding)

————Personal notes are for reference only

おすすめ

転載: blog.csdn.net/weixin_51114236/article/details/125875668