抱歉打扰了,是我个人疏忽,这个问题可以参照管道通配符和UNION ALL的优先级文档中的内容,我在UNION ALL完了之后还做了一个GROUP BY,所以正常的解决办法应该时在UNION ALL的左侧和右侧语句外边加一个括号,再去做GROUP BY,具体如下:
$a=GO 1 TO 2 STEPS FROM "27493" OVER person_knows_person YIELD dst(edge) AS dst; \
(GO FROM $a.dst OVER person_isLocatedIn_place WHERE properties($$).type == "city" YIELD src(edge) AS src,properties($^).firstName AS personFirstName,properties($^).lastName AS personLastName,dst(edge) AS dst | \
GO FROM $-.dst OVER place_isPartOf_place WHERE properties($$).name != "Papua_New_Guinea" AND properties($$).name != "Switzerland" YIELD $-.src AS src,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GO FROM $-.src OVER comment_hasCreator_person,post_hasCreator_person REVERSELY YIELD id($$) AS messageID,$-.src AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GO FROM $-.messageID OVER comment_isLocatedIn_place,post_isLocatedIn_place WHERE properties($$).type == "country" AND properties($$).name == "Switzerland" YIELD $-.messageID AS messageID,$-.personID AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GROUP BY $-.personID,$-.personFirstName,$-.personLastName YIELD $-.personID AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName,count(*) AS xCount,0 AS yCount \
UNION ALL \
GO FROM $a.dst OVER person_isLocatedIn_place WHERE properties($$).type == "city" YIELD src(edge) AS src,properties($^).firstName AS personFirstName,properties($^).lastName AS personLastName,dst(edge) AS dst | \
GO FROM $-.dst OVER place_isPartOf_place WHERE properties($$).name != "Papua_New_Guinea" AND properties($$).name != "Switzerland" YIELD $-.src AS src,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GO FROM $-.src OVER comment_hasCreator_person,post_hasCreator_person REVERSELY YIELD id($$) AS messageID,$-.src AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GO FROM $-.messageID OVER comment_isLocatedIn_place,post_isLocatedIn_place WHERE properties($$).type == "country" AND properties($$).name == "Papua_New_Guinea" YIELD $-.messageID AS messageID,$-.personID AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName | \
GROUP BY $-.personID,$-.personFirstName,$-.personLastName YIELD $-.personID AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName,0 AS xCount,count(*) AS yCount) | \
GROUP BY $-.personID,$-.personFirstName,$-.personLastName AS personLastName YIELD $-.personID AS personID,$-.personFirstName AS personFirstName,$-.personLastName AS personLastName,sum($-.xCount) AS xCount,sum($-.yCount) AS yCount,(sum($-.xCount)+sum($-.yCount)) AS count | \
ORDER BY $-.personID asc,$-.count desc | LIMIT 20