SELECT X(Coordinates) AS `latitude`, Y(Coordinates) AS `longitude`, `AtcoCode` AS `atcocode`, `CommonName` as `name`,
(
SELECT COUNT(`jptl`.`id`)
FROM `a`.`jps` `jptl`
JOIN `a`.`journpat` `jp` ON `jp`.`journey_pattern_section_reference` = `jptl`.`journey_pattern_section_reference`
JOIN `a`.`serv` ON `service`.`reference` = `jp`.`service_reference`
JOIN `a`.`op` ON `operator`.`reference` = `service`.`operator_reference`
JOIN `a`.`operator` `fmbo` ON fmbo.operator_reference = operator.reference
WHERE `jptl`.`stop_from` = AtcoCode
) AS subscriber
FROM `a`.`qwerty`
WHERE MBRContains(
GeomFromText( concat('LINESTRING(',50.922538,-1.301773,',',50.916856,-1.306708,')') ),
Coordinates)
如果subscriber
的值大于1,则subscriber
值应为true,否则应为false。我怎么能这样做?
答案 0 :(得分:1)
您可以使用IF
:
... as `name`, IF((... your query here) > 1, true, false) AS `subscriber`...
另一个选项是修改子查询,并将count(*)
与1:
... SELECT COUNT(jptl
。id
)> 1 ...
但是原始查询将返回1或0,但大多数ORM会将其解释为TRUE
或FALSE
(如果您使用的话)