如何在Zend JOIN中编写WHERE子句?

时间:2011-08-02 09:39:48

标签: php zend-framework

我想在Zend写这个查询...请帮帮我......

SELECT DISTINCT substr(A.REPORTED_DATE,0,10) AS REPORTED_DATE , COUNT(DISTINCT A.ISSUE_ID) AS ISSUE_COUNT
        FROM ABACUS_ISSUE A
        JOIN ABACUS_ISSUE_HISTORY B ON A.ISSUE_ID = B.ISSUE_ID AND B.FIELD_ID = 2028
        AND (
                 B.OLD_VALUE IN (2,13)
                 AND B.NEW_VALUE = 8 OR A.STATE IN(2,13,10)
            )
        WHERE
        (
            A.ISSUE_TYPE = 1
            AND A.ISSUE_SUB_TYPE_ID = 10
        )
        AND PARENT_ISSUE_ID = -1
        AND A.PROJECT_ID = 'Tullett'

1 个答案:

答案 0 :(得分:2)

这样的事情应该有效:

$select = $db->select()
    ->from(
        array('A' => 'ABACUS_ISSUE'),
        array('DISTINCT substr(A.REPORTED_DATE,0,10) AS REPORTED_DATE', 'COUNT(DISTINCT A.ISSUE_ID) AS ISSUE_COUNT')
    )
    ->join(
        array('B' => 'ABACUS_ISSUE_HISTORY'),
        'A.ISSUE_ID = B.ISSUE_ID AND B.FIELD_ID = 2028 AND ( B.OLD_VALUE IN (2,13) AND B.NEW_VALUE = 8 OR A.STATE IN(2,13,10) )',
        array()
    )
    ->where('A.ISSUE_TYPE = ?', 1)
    ->where('A.ISSUE_SUB_TYPE_ID = ?', 10)
    ->where('PARENT_ISSUE_ID = ?', -1)
    ->where('A.PROJECT_ID = ?', 'Tullett');

$rows = $select->query()->fetchAll();

请阅读the docs