简体   繁体   中英

How to write the WHERE-clause inside the Zend JOIN?

I want to write this query in Zend ...please help me...

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'

Something like this should work:

$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();

Read the docs please.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM