2017-09-13 72 views
0

當我在PostgreSQL中執行MySQL查詢它顯示。我已經在谷歌搜索有關該錯誤的錯誤,但他們沒有工作me.Please建議我來解決。如何更改MySQL查詢到PostgreSQL查詢

下面

是MySQL查詢:

SELECT caller_id_number, 
     caller_id_name, 
     dialed_number, 
     count(*) NumberOfCalls, 
     round(sum(duration_seconds)/60,2) CallDurationMin 
FROM kazoo_cdr_rpt 
WHERE cdr_date_time > '20-08-2017' 
    AND cdr_date_time < 24-08-2017 
    AND length(caller_id_number) < 5 
    AND direction = "outbound" 
GROUP BY dialed_number; 

,當我在Postgres的執行上面的查詢是得到錯誤的

round(sum(durati... 
                  ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 
+2

什麼是您的具體問題? Postgre不是MySQL,所以你不能期望工作。錯誤消息告訴你爲什麼:你正在使用的函數沒有在Postgre中定義,所以檢查你的MySQL函數Postgre是什麼。 – datell

+0

你能提出什麼是圓使用PostgreSQL中工作的功能(總和(DURATION_SECONDS)/ 60,2) –

+0

你的錯誤看起來很奇怪 - 能否請您複製/粘貼異常的全部文本.. –

回答

0

如果你的持續時間第二個是varchar,你將不得不轉換它以一個數字:

SELECT caller_id_number, 
     caller_id_name, 
     dialed_number, 
     count(*) NumberOfCalls, 
     round(sum(CAST(duration_seconds as numeric))/60,2) CallDurationMin 
FROM kazoo_cdr_rpt 
WHERE cdr_date_time > '20-08-2017' 
    AND cdr_date_time < '24-08-2017' 
    AND length(caller_id_number) < 5 
    AND direction = "outbound" 
GROUP BY caller_id_number, caller_id_name, dialed_number; 
+0

錯誤:函數round(double precision,integer)不存在 LINE 5:round(sum(CAST(duration_seconds as float) )/ 60,2)呼叫.. –

+0

我得到上面的錯誤,當我執行查詢 –

+0

對不起,錯投。我糾正了我的答案。 'cast(... as numeric)'而不是float。 –