将带有子选择的 MySQL 查询转换为 Zend 格式

发布于 2024-11-26 16:10:31 字数 1281 浏览 1 评论 0原文

我想将此 MySQL 查询翻译为 Zend 格式:

SELECT count_panne, mvt, nextHost, dtmvt, stat  
FROM ( SELECT COUNT(myTable.snMCB) AS count_panne,  
        myTable.mvt,  
        myTable.nextHost,  
        myTable.dtmvt,  
        myTable.stat  
    FROM myDB.myTable myTable  
    WHERE (myTable.dtmvt = calendar__gregorian__today__)  
      AND (myTable.statut = 'NOOK')  
    GROUP BY myTable.snMCB) AS myTempTable  
 WHERE count_panne > 2  
 ORDER BY count_panne DESC   

(ps:这是带有修改的正确 mysql 句子)

我用 Zend 尝试了以下操作:

$subSelect = $dbTable->select()  
    ->from($dbTable,array(
        'COUNT(myTable.snMCB) AS count_panne',
        'myTable.mvt',
        'myTable.nextHost',
        'myTable.dtmvt',
        'myTable.nextHost'))
    ->where("myTable.dtmvt BETWEEN '$dateDeb' AND '$dateFin'")
    ->where('myTable.stat = ?', 'NOOK')
    ->group('myTable.snMCB')
    ;

$select = $dbTable->select()
    ->setIntegrityCheck(false)
    ->from(new Zend_Db_Expr($subSelect),
            array('count_panne',
                'mvt',
                'nextHost',
                'dtmvt',
                'statut'))
    ->where('count_panne > 2')
    ->order('count_panne DESC')
    ;

它不起作用。

I would like to translate this MySQL query to the Zend format:

SELECT count_panne, mvt, nextHost, dtmvt, stat  
FROM ( SELECT COUNT(myTable.snMCB) AS count_panne,  
        myTable.mvt,  
        myTable.nextHost,  
        myTable.dtmvt,  
        myTable.stat  
    FROM myDB.myTable myTable  
    WHERE (myTable.dtmvt = calendar__gregorian__today__)  
      AND (myTable.statut = 'NOOK')  
    GROUP BY myTable.snMCB) AS myTempTable  
 WHERE count_panne > 2  
 ORDER BY count_panne DESC   

(ps: That's a correct mysql sentence with modifs)

I tried the following with Zend:

$subSelect = $dbTable->select()  
    ->from($dbTable,array(
        'COUNT(myTable.snMCB) AS count_panne',
        'myTable.mvt',
        'myTable.nextHost',
        'myTable.dtmvt',
        'myTable.nextHost'))
    ->where("myTable.dtmvt BETWEEN '$dateDeb' AND '$dateFin'")
    ->where('myTable.stat = ?', 'NOOK')
    ->group('myTable.snMCB')
    ;

$select = $dbTable->select()
    ->setIntegrityCheck(false)
    ->from(new Zend_Db_Expr($subSelect),
            array('count_panne',
                'mvt',
                'nextHost',
                'dtmvt',
                'statut'))
    ->where('count_panne > 2')
    ->order('count_panne DESC')
    ;

It didn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-12-03 16:10:31

您是否尝试过直接使用 db adpater 和 sql 来执行此操作,如...

    $db = $this->getAdapter();

$query = $db->prepare("SELECT count_panne, mvt, nextHost, dtmvt, stat  
                       FROM ( SELECT COUNT(myTable.snMCB) AS count_panne,  
                             myTable.mvt,  
                             myTable.nextHost,  
                             myTable.dtmvt,  
                             myTable.stat  
                        FROM myDB.myTable myTable  
                       WHERE (myTable.dtmvt = calendar__gregorian__today__)  
                         AND (myTable.statut = 'NOOK')  
                       GROUP BY myTable.snMCB) AS myTempTable  
                       WHERE count_panne > 2  
                    ORDER BY count_panne DESC");

        $query->execute();
        return $query->fetchAll();

Have you tried doing this using the db adpater direct with sql as in...

    $db = $this->getAdapter();

$query = $db->prepare("SELECT count_panne, mvt, nextHost, dtmvt, stat  
                       FROM ( SELECT COUNT(myTable.snMCB) AS count_panne,  
                             myTable.mvt,  
                             myTable.nextHost,  
                             myTable.dtmvt,  
                             myTable.stat  
                        FROM myDB.myTable myTable  
                       WHERE (myTable.dtmvt = calendar__gregorian__today__)  
                         AND (myTable.statut = 'NOOK')  
                       GROUP BY myTable.snMCB) AS myTempTable  
                       WHERE count_panne > 2  
                    ORDER BY count_panne DESC");

        $query->execute();
        return $query->fetchAll();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文