0
我有一个SQL查询,我试图将其转换为DQL。看起来像DQL不喜欢在FROM子句中使用子查询。你能指导我的方向吗?Doctrine查询语言中的子查询
SQL:
select count(x.remote_addr), ipc.country
from
(
select distinct(remote_addr) from update_feature_requests ufr
where ufr.request_datetime BETWEEN '2015-05-14' AND '2015-05-15'
)
as x
join ip_geolocation_cache ipc ON ipc.ip_address = x.remote_addr
group by ipc.country;
DQL:
$dql = "select
count(x.remoteAddr), ipc.country
from
(
select distinct(remoteAddr) from " . UpdateFeatureRequest::class . " ufr
where ufr.requestDatetime BETWEEN '2015-05-14' AND '2015-05-15'
)
as x
join " . IpGeolocationCache::class . " ipc ON ipc.ipAddress = x.remoteAddr
group by ipc.country";
Doctrine \ ORM \ Query \ QueryException HELP [Semantical Error] line 0, col 82 near '(': Error: Class '(' is not defined.
非常感谢,非常感谢。我相信你的sql也应该比我的更快。它应该很容易理解它:-)我会记住Doctrine –
的这种限制不一定要更快:)根据结构,但yor子查询可以物化为简单的索引扫描,MariaDB甚至可以合并将子查询自动地添加到外部查询中(看起来像这个在MySQL 5.6中尚不可用) – jkavalik