是否可以在 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中工作吗?