如何将此SQL语句转换为PostgreSQL?

时间:2015-12-11 09:38:34

标签: mysql sql postgresql

我有一个不能在PostgreSQL服务器上运行的MySQL语句。

这是最初的MySQL查询:

SELECT count(*) AS howmany 
FROM members 
WHERE member_status =1 
AND member_sex = 'male' 
AND (YEAR( '2015-12-31' ) - YEAR( member_birthdate ) ) - 
    ( RIGHT( '2015-12-31', 5 ) < RIGHT( member_birthdate, 5 ) ) 
BETWEEN 27 AND 40;

这是我的方法:

SELECT COUNT(*) AS howmany FROM members
WHERE member_status =1 
AND member_sex ='male'
AND (EXTRACT(YEAR FROM '2015-12-31'::date) - EXTRACT(YEAR FROM member_birthdate)) 
BETWEEN 27 AND 40;

目标是,我想知道在2015-12-31的排位日期有多少会员年龄在27到40岁之间。 我不知道如何转换查询的右侧部分。

1 个答案:

答案 0 :(得分:5)

您可以使用AGE功能:

$rootScope.$on('newArticleAdded', function(event, data) {
          // get all article details generated by the back-end and add it to he grid
        });