【发布时间】:2017-03-28 19:36:10
【问题描述】:
SELECT apntoken,deviceid,created
FROM `distribution_mobiletokens` as dm
WHERE userid='20'
and not exists (
select 1
from `distribution_mobiletokens`
where userid = '20'
and deviceid = dm.deviceid
and created > dm.created
)
此查询的作用是选择用户 ID 等于 20 且设备 ID 相同但为设备选择最新的 apntoken 的所有移动令牌。
我的数据库如下所示。
有关此查询的更多信息,我从我在这里提出的另一个问题中得到了这个答案(How to group by in SQL by largest date (Order By a Group By))
我尝试过的事情
$mobiletokens = $em->createQueryBuilder()
->select('u.id,company.id as companyid,user.id as userid,u.apntoken')
->from('AppBundle:MobileTokens', 'u')
->leftJoin('u.companyId', 'company')
->leftJoin('u.userId', 'user')
->where('u.status = 1 and user.id = :userid')
->setParameter('userid',(int)$jsondata['userid'])
->groupby('u.apntoken')
->getQuery()
->getResult();
//@JA - Get the list of all the apn tokens we need to send the message to.
foreach($mobiletokens as $tokenobject){
$deviceTokens[] = $tokenobject["apntoken"];
echo $tokenobject["apntoken"]."\n";
}
die();
这给了我不正确的反应
63416A61F2FD47CC7B579CAEACB002CB00FACC3786A8991F329BB41B1208C4BA
9B25BBCC3F3D2232934D86A7BC72967A5546B250281FB750FFE645C8EB105AF6
latestone
感谢您的帮助!
其他信息
SELECT * FROM 的数据
使用我提供的 SQL 后的数据。
【问题讨论】:
-
如果我错过了任何有用的信息,请告诉我,我还在做更多的研究,在这种情况下不使用 DQL 并使用直接 SQL 的最佳方法是什么?
标签: mysql symfony doctrine-orm dql doctrine-query