0

我使用 Sparx EA 构建关系数据库(MS SQL Server)。

该工具具有创建图表的功能。

我使用查询:

SELECT system.Name AS Series, systemElement.Name AS GroupName
FROM t_object systemElement
INNER JOIN t_object system ON system.Object_ID = systemElement.ParentID
INNER JOIN t_object organization ON organization.ParentID = systemElement.Object_ID
INNER JOIN t_object post ON post.ParentID = organization.Object_ID AND post.Stereotype = 'ActualPost'

WHERE system.Name = 'Name of my main system object'

要得到

在此处输入图像描述

这很好,只是因为图表没有说明 ActualPosts 的多样性。

我可以访问多样性

SELECT system.Name AS Series, systemElement.Name AS GroupName, post.Name AS 'ActualPost', post.Multiplicity AS 'Multiplicity'
FROM t_object systemElement
INNER JOIN t_object system ON system.Object_ID = systemElement.ParentID
INNER JOIN t_object organization ON organization.ParentID = systemElement.Object_ID
INNER JOIN t_object post ON post.ParentID = organization.Object_ID AND post.Stereotype = 'ActualPost'

WHERE system.Name = 'Name of my main system object'

结果如下表:

Series | GroupName | ActualPost | Multiplicity
Name of my main system element | OperationalPerformer A | Post AA | 1
Name of my main system element | OperationalPerformer A | Post AB | 1
Name of my main system element | OperationalPerformer A | Post AC | 2
Name of my main system element | OperationalPerformer B | Post BA | 1
Name of my main system element | OperationalPerformer B | Post BB | 1
Name of my main system element | OperationalPerformer C | Post CA | 3
Name of my main system element | OperationalPerformer C | Post CB | 2
Name of my main system element | OperationalPerformer C | Post CC | 5

我在想的是把多重性添加为行,所以把一张桌子变成这样:

Series | GroupName | ActualPost| Multiplicity
Name of my main system element | OperationalPerformer A | Post AA | 1
Name of my main system element | OperationalPerformer A | Post AB | 1
Name of my main system element | OperationalPerformer A | Post AC | 2

进入

Series | GroupName
Name of my main system element | OperationalPerformer A
Name of my main system element | OperationalPerformer A
Name of my main system element | OperationalPerformer A
Name of my main system element | OperationalPerformer A

虽然我不知道该怎么做。

有什么想法吗?

谢谢!

更新:

似乎 Sparx EA 在 SQL 查询方面有一些限制......查询必须以 select 开头,请参阅EA Sparx 查询中的 WITH 子句

提供的答案是否有解决方法?

4

2 回答 2

2

如果Multiplicity <= 2047

WITH myTable as (
    SELECT system.Name AS Series, systemElement.Name AS GroupName, post.Name AS 'ActualPost', post.Multiplicity AS 'Multiplicity'
    FROM t_object systemElement
    JOIN t_object system 
      ON system.Object_ID = systemElement.ParentID
    JOIN t_object organization 
      ON organization.ParentID = systemElement.Object_ID
    JOIN t_object post 
      ON post.ParentID = organization.Object_ID AND post.Stereotype = 'ActualPost'
    WHERE system.Name = 'Name of my main system object'
)
SELECT
    Series, GroupName
FROM
    myTable m
    JOIN master.dbo.spt_values v on m.Multiplicity > v.number
WHERE
    Type = 'P'

修改CTEDerived Table检查这一点

SELECT
    Series, GroupName
FROM (
    SELECT system.Name AS Series, systemElement.Name AS GroupName, post.Name AS 'ActualPost', post.Multiplicity AS 'Multiplicity'
    FROM t_object systemElement
    JOIN t_object system 
      ON system.Object_ID = systemElement.ParentID
    JOIN t_object organization 
      ON organization.ParentID = systemElement.Object_ID
    JOIN t_object post 
      ON post.ParentID = organization.Object_ID AND post.Stereotype = 'ActualPost'
    WHERE system.Name = 'Name of my main system object'
) DT
    JOIN MASTER.dbo.spt_values v on DT.Multiplicity > v.number
WHERE
    Type = 'P'

于 2021-04-09T13:33:28.663 回答
0
;WITH T1 AS (
    SELECT
        system.Name AS Series,
        systemElement.Name AS GroupName,
        post.Multiplicity AS 'Multiplicity',
        1 as Cnt
    FROM t_object systemElement
        INNER JOIN t_object system ON system.Object_ID = systemElement.ParentID
        INNER JOIN t_object organization ON organization.ParentID = systemElement.Object_ID
        INNER JOIN t_object post ON post.ParentID = organization.Object_ID AND post.Stereotype = 'ActualPost'
    WHERE system.Name = 'Name of my main system object'

    UNION ALL

    SELECT
        Series,
        GroupName,
        Multiplicity,
        Cnt + 1 AS Cnt
    FROM T1
    WHERE Cnt < Multiplicity
)
SELECT
    Series,
    GroupName
FROM T1
OPTION (MAXRECURSION 0) -- set recursion limit to undefined
于 2021-04-09T13:32:06.493 回答