此查詢的工作......INSERT查詢中的數據到現有的表
SELECT Round(((SELECT Count(*)
FROM nps_surveys
WHERE score >= 9
AND social = 0
AND Date(completedon) >= Last_day(CURRENT_DATE) +
INTERVAL 1 day
- INTERVAL 1 month)/
(SELECT Count(score)
FROM nps_surveys
WHERE score IS NOT NULL
AND social = 0
AND Date(completedon) >= Last_day(
CURRENT_DATE) +
INTERVAL 1 day
-
INTERVAL 1 month) *
100) - ((SELECT Count(*)
FROM nps_surveys
WHERE score >= 0
AND score <= 6
AND social = 0
AND Date(completedon) >= Last_day(CURRENT_DATE)
+
INTERVAL 1
day
- INTERVAL 1 month)/
(SELECT Count(score)
FROM nps_surveys
WHERE score IS NOT NULL
AND social = 0
AND Date(completedon) >= Last_day(
CURRENT_DATE)
+
INTERVAL
1 day
-
INTERVAL 1 month) *
100)) nps;
但是這一次不...
SELECT cast(round((
(
SELECT Count(*)
FROM nps_surveys
WHERE score >= 9
AND social = 0
AND Date(completedon) >= Last_day(CURRENT_DATE) + interval 1 day - interval 1 month)/
(
SELECT count(score)
FROM nps_surveys
WHERE score IS NOT NULL
AND social = 0
AND date(completedon) >= last_day(CURRENT_DATE) + interval 1 day - interval 1 month)*100) - (
(
SELECT count(*)
FROM nps_surveys
WHERE score >=0
AND score <= 6
AND social = 0
AND date(completedon) >= last_day(CURRENT_DATE) + interval 1 day - interval 1 month)/
(
SELECT count(score)
FROM nps_surveys
WHERE score IS NOT NULL
AND social = 0
AND date(completedon) >= last_day(CURRENT_DATE) + interval 1 day - interval 1 month)*100)) nps;
我保持You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nps' at line 1
運行時得到一個錯誤,但它沒有意義,因爲唯一的區別是cast
函數。我試着插入已知的工作上面的查詢到我的Python腳本沒有的cast
,它在我太樹皮。
當我打開用'SELECT CAST(括號。 ..'並且不要關閉它,我得到一個錯誤:'你的SQL語法有錯誤;查看與你的MySQL服務器版本相對應的手冊,以便在'1'附近'nps'使用正確的語法。 –
@JohnF這就是我的觀點,你已經表明你正在執行一個函數調用''cast(...'但你永遠不會關閉它 - 這是消息指出的語法錯誤。 – EyuelDK
@EyueIDK當我添加諸如'nps);'這樣的結束'''時,它仍然返回一個錯誤。 –