是否可以在EA Sparx查询中使用WITH子句?
我写了这个:
with Activities as
(
select t_connector.start_object_id as Object2_id, t_object.* from t_object
join t_connector on t_connector.end_object_id=t_object.Object_id
where t_object.Object_type= 'Activity'
union
select t_connector.end_object_id as Object2_id, t_object.* from t_object
join t_connector on t_connector.start_object_id=t_object.Object_id
where t_object.Object_type= 'Activity'
)
select * from
(
select obj.object_id, count(other.object_id) as 'Activities' from
t_object obj left join Activities as other on obj.Object_id=other.Object2_id
group by obj.object_id
) as ac
where object_id in (143306, 143321, 143226, 143326)
它不返回任何行也不会引发任何错误,而将WITH语句放在行内的同一查询将返回预期结果:
select * from
(
select obj.object_id, count(other.object_id) as 'Activities' from
t_object obj left join
(
select t_connector.start_object_id as Object2_id, t_object.* from t_object
join t_connector on t_connector.end_object_id=t_object.Object_id
where t_object.Object_type= 'Activity'
union
select t_connector.end_object_id as Object2_id, t_object.* from t_object
join t_connector on t_connector.start_object_id=t_object.Object_id
where t_object.Object_type= 'Activity'
)
as other on obj.Object_id=other.Object2_id
group by obj.object_id
) as ac
where object_id in (143306, 143321, 143226, 143326)
我知道EA的SQL引擎有些棘手(例如,查询不能以注释开头)。
这里有一些技巧可以让WITH子句在EA中起作用吗?
答案 0 :(得分:1)
EA对查询进行了一些基本检查。其中之一是检查查询是否以关键字select
开头。
因此,没有办法让EA以select
之后的其他名称开始执行搜索查询。
在许多情况下,WITH
子句用于执行递归查询,例如获取包及其所有子包中的所有元素。
对于这种特定情况,您可以使用宏#Branch#
,该宏将递归转换为当前所选软件包及其所有子软件包的packageID的逗号分隔列表。