多个部门的个人影响总数

发布于 2025-02-13 19:32:49 字数 2025 浏览 0 评论 0原文

我有一份报告要简化,但我遇到了一个问题。

(不希望的)报告的行/列当前看起来如下。

部门缓刑(%)暂停(%)
所有员工3216.31.4
所有团队3023.52.2
总男队总男队1014.82.8
总女队总数34.31.4男士
10穿着105.90.0
女装1021.40.0
Unisec1015.06.3

Wear 因为两个人在两个团队中工作。一个人穿着男装穿着和男女通用的服装工作,一个人在女装和男女通用服装中工作。下表有这样的记录。

COL1COL2
1234男士穿着
1234男女通用的
9876男女
女装9876通用磨损

(期望)我正在寻找类似的东西。

部门缓刑(%)暂停(%)
所有员工3016.31.4
所有团队3023.52.2
总男队1014.82.8
总妇女团队1034.31.4
男士穿着105.90.9 0.0
女装1021.40.0
UNISEC WEAL1015.06.3

我以为关于在Col2上使用ListAgg()来获得这种影响。

COL1COL2
1234男装,男女通用的
9876女装,

使用Listagg()使用UniSEX WEAR为“所有员工”提供了正确的计数,但随后我得到了“男士穿着,男女求衣服”的分组”和“男女通用磨损”。是否可以按照Listagg()'ed Listagg()'ed,或者有更好的方法来实现我的最终结果后,通过单独的逗号分隔值分组?

实现这一目标的任何帮助将不胜感激。

I have a report I am trying to simplify but I am running into an issue.

(Undesired) The rows/columns of the report currently look like the following.

DepartmentTotalProbation (%)Suspended (%)
All Employees3216.31.4
All Teams3023.52.2
Total Men's Teams1014.82.8
Total Women's Teams1034.31.4
Men's Wear105.90.0
Women's Wear1021.40.0
UniSec Wear1015.06.3

This is happening because two people work on two teams. One person works in Mens Wear and UniSex Wear, and one person works in Women's Wear and UniSex Wear. The below table has records like this.

Col1Col2
1234Men's Wear
1234UniSex Wear
9876Women's Wear
9876UniSex Wear

(Desired) Im looking for something like this.

DepartmentTotalProbation (%)Suspended (%)
All Employees3016.31.4
All Teams3023.52.2
Total Men's Teams1014.82.8
Total Women's Teams1034.31.4
Men's Wear105.90.0
Women's Wear1021.40.0
UniSec Wear1015.06.3

I have thought about using LISTAGG() on Col2 to get this affect.

Col1Col2
1234Men's Wear,UniSex Wear
9876Women's Wear,UniSex Wear

Using LISTAGG() gives me the correct count for "All Employees" but then I get groupings of "Men's Wear,UniSex Wear" instead of a separate one for "Men's Wear" and one for "UniSex Wear". Is it possible to group by the individual comma separated values in Col2 after they have been LISTAGG()'ed, or is there a better way of achieving my end results?

Any assistance on achieving this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰ツ都不明白 2025-02-20 19:32:49

我建议单独纠正All_employes数据,而不是进行ListAgg。
或者
使用一个单独的表来列表和un-listagg您的数据,这与用于计算UN-Listagg的总数,缓刑和悬挂数据的原始表不同

您可以使用以下示例,其中Table_two是您的源表。

    with  
    d2 as (
      select 
        distinct id, 
        regexp_substr(
          products, '[^,]+', 1, column_value
        ) as products 
      from 
        table_two cross 
        join TABLE(
          Cast(
            MULTISET (
              SELECT 
                LEVEL 
              FROM 
                dual CONNECT BY level <= REGEXP_COUNT(products, '[^,]+')
            ) AS sys.ODCINUMBERLIST
          )
        )
    ) 
    SELECT 
      ID, 
      PRODUCTS 
    FROM 
      d2;

I would advise correcting the All_Employees data alone instead of doing the LISTAGG.
OR
Use a separate table to LISTAGG and un-LISTAGG your data which is different from the original table used to calculate the Total, Probation and Suspended data

For un-LISTAGG you can use the below example where table_two is your source table.

    with  
    d2 as (
      select 
        distinct id, 
        regexp_substr(
          products, '[^,]+', 1, column_value
        ) as products 
      from 
        table_two cross 
        join TABLE(
          Cast(
            MULTISET (
              SELECT 
                LEVEL 
              FROM 
                dual CONNECT BY level <= REGEXP_COUNT(products, '[^,]+')
            ) AS sys.ODCINUMBERLIST
          )
        )
    ) 
    SELECT 
      ID, 
      PRODUCTS 
    FROM 
      d2;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文