今天在寫項目的時候,遇到了一個比價頭疼的問題:
ifnull.............
No function matches the given name and argument types. You might need to add explicit type casts
現在公司用的是postgrepsql數據庫,自己用navicat連接的,屁顛屁顛的還當是mysql的函數語法來用的,扣了半天,原來才發現,pg數據庫中根本就沒有ifnull這個函數,
可以使用COALESCE函數代替。
這是改正確之后的sql語句:
SELECT tt.NAME, tt.sex, tt.idcardtype, tt.idcard, tt.mobile , tt.birthday, tt.ID, tt.vipid, tt.cardno, tt.cardtypename , tt.cardtypecode, tt.gradetypename, tt.status, tt.TYPE, tt.changecardno , tt.changecardnoflag, tt.PASSWORD, tt.accountmoneytype, tt.networktype, tt.usertype , tt.money, tt.points, tt.couponcnt, tt.relatedcnt, COALESCE ( tt.comname, tt.unitname ) as unitname, tt.refereecode, tt.insuretype, tt.starteffectdate, tt.endeffectdate, tt.uniagentcode, tt.unisaleschannel , tt.unisalesbusitype FROM ( SELECT vip.NAME, vip.sex, vip.idcardtype, vip.idcard, vip.mobile , vip.birthday, acc.ID, acc.vipid , CASE WHEN acc.cardno IS NULL THEN acc.changecardno ELSE acc.cardno END AS cardno, acc.cardtypename, acc.cardtypecode, acc.gradetypename, acc.status , acc.TYPE, acc.changecardno, acc.changecardnoflag, acc.PASSWORD, acc.accountmoneytype , acc.networktype, acc.usertype, mon.money, mon.points , CASE WHEN cp.couponcnt IS NULL THEN 0 ELSE cp.couponcnt END AS couponcnt , ( SELECT COUNT(0) FROM vip_accountrelated T WHERE T.vipid = vip.ID AND T.accountid = acc.ID AND T.dr = 0 ) AS relatedcnt , ( SELECT t1.unit_name::VARCHAR FROM up_org_unit t1, up_org_unit_ext t2 WHERE t1.unit_id = t2.unit_id AND t2.unit_uncode = vip.unitid ) AS unitname , ( SELECT t1.unit_name::VARCHAR FROM up_org_unit t1, up_org_unit_ext t2 WHERE t1.unit_id = t2.unit_id AND t2.unit_uncode = acc.sendunitid ) AS comname, acc.refereecode, vip.insuretype, acc.starteffectdate, acc.endeffectdate , acc.uniagentcode, acc.unisaleschannel, acc.unisalesbusitype FROM VIP_ACCOUNT acc, VIP_INFO vip, VIP_ACCOUNTMONEY mon, ( SELECT ac.accountid, COUNT(0) AS couponcnt FROM VIP_ACCOUNTCOUPON ac, VIP_COUPON cou WHERE ac.couponcode = cou.code AND cou.status = 1 AND ac.dr = 0 AND cou.dr = 0 GROUP BY ac.accountid ) cp WHERE acc.vipid = vip.ID AND acc.ID = mon.ID AND acc.ID = cp.accountid AND acc.dr = 0 AND vip.dr = 0 AND mon.dr = 0 ) tt ORDER BY tt.usertype OFFSET ( ?- 1 ) * ? LIMIT ?
推薦一個網址:產看pgsql常用的函數: