简体   繁体   中英

How do I change the following query to a Zend Framework (1) query?

Hello I have a working query but I'm kinda new to Zend how can I change the query below to a zend query?

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

something Like this?, not tested,

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

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