您好,我有一个有效的查询,但是对Zend有点陌生,如何将下面的查询更改为zend查询?

SELECT
user_dob,
user_dob + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(user_dob)) + 0 YEAR AS currbirthday
FROM user
ORDER BY CASE WHEN currbirthday < CURRENT_TIMESTAMP
THEN currbirthday + INTERVAL 1 YEAR
ELSE currbirthday
END
LIMIT 4

最佳答案

像这样的东西?未经测试,

$select = $sql->select ('user');

$select->columns(array(
            'user_dob',
            'currbirthday' => new Expression('user_dob + INTERVAL(YEAR(CURRENT_TIMESTAMP) - YEAR(user_dob)) + 0 YEAR')))
->order (
    new Expression('
        CASE WHEN currbirthday < CURRENT_TIMESTAMP
        THEN currbirthday + INTERVAL 1 YEAR
        ELSE currbirthday
        END'
    )
);

关于php - 如何将以下查询更改为Zend Framework(1)查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22089824/

10-12 15:01