我有一個MySQL語句,它不會在PostgreSQL服務器上運行。如何將此SQL語句轉換爲PostgreSQL?
原來這裏是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;
的目標是什麼,我想知道有多少成員年27至40歲之間的資格日期2015-12-31。 我不知道如何轉換查詢的右側部分。
你得到什麼錯誤?或者發佈一些我們可以使用的示例數據 – Matt