doulao2029 2014-09-23 12:24
浏览 28
已采纳

zend left join count not working [关闭]

ia have a problem with count in multi joins

$query = $this->select()
        ->setIntegrityCheck(false)
        ->from(array('u' => 'users'))
        ->join(array('c' => 'clients'), 'u.id = c.user_id', 'COUNT(c.user_id) as clientsCount')
        ->join(array('emails' => 'u_emails'), 'u.id = emails.user_id', 'COUNT(emails.user_id) as emailsCount')
        ->join(array('sms' => 'u_sms'), 'u.id = sms.user_id', 'COUNT(sms.user_id) as smsCount')
        ->where('u.id=?', (int) USER_ID)->group('u.id');
  • 写回答

1条回答 默认 最新

  • dtvam48220 2014-09-23 14:48
    关注

    I think this can help you out of this problem:

    $this->select()
         ->from(array('u' => 'users'), array(
                'clientsCount' => new Zend_Db_Expr("(SELECT COUNT(*) FROM clients WHERE clients.user_id = u.id)"),
                'emailsCount' => new Zend_Db_Expr("(SELECT COUNT(*) FROM emails WHERE emails.user_id = u.id)"),
                'smsCount' => new Zend_Db_Expr("(SELECT COUNT(*) FROM sms WHERE sms.user_id = u.id)"),
         )
         ->where('u.id=?', (int) USER_ID)
         ->group('u.id');
    

    I can't test the query so feel free to ask if you have any problems.

    Edited my answer, please try it again

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: