我刚刚在 Windows 10 上设置了 Bash,安装了 libmysqlclient-dev 包并正在运行一个执行以下查询的 rake 任务,以使用 ActiveRecord::Base.connection.execute 在 mysql 数据库上创建一个 VIEW
DROP TABLE IF EXISTS debtors_customer_balances;
CREATE OR REPLACE VIEW debtors_customer_balances AS
SELECT
customer_id,
SUM(amount_cents) AS total_cents,
SUM(CASE
WHEN due_on >= CURDATE()
THEN amount_cents
ELSE 0
END) AS current_cents,
SUM(CASE
WHEN due_on >= (CURDATE() - INTERVAL 7 DAY)
AND due_on < CURDATE()
THEN amount_cents
ELSE 0
END) AS overdue7_cents,
SUM(CASE
WHEN due_on >= (CURDATE() - INTERVAL 14 DAY)
AND due_on < (CURDATE() - INTERVAL 7 DAY)
THEN amount_cents
ELSE 0
END) AS overdue14_cents,
SUM(CASE
WHEN due_on >= (CURDATE() - INTERVAL 30 DAY)
AND due_on < (CURDATE() - INTERVAL 14 DAY)
THEN amount_cents
ELSE 0
END) AS overdue30_cents,
SUM(CASE
WHEN due_on < (CURDATE() - INTERVAL 30 DAY)
THEN amount_cents
ELSE 0
END) AS overdue30_plus_cents
FROM
debtors_balances
GROUP BY
customer_id;
但是,它抛出一个错误
Mysql2::Error: 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的“CREATE OR REPLACE VIEW debtors_customer_balances AS SELECT”附近使用正确的语法:DROP TABLE IF EXISTS debtors_customer_balances; 创建或替换视图债务人_客户_余额作为选择客户_ID等...
我无法弄清楚是什么导致了这种情况,因为查询在 Mac 上运行良好,它只是在 Windows 的 bash 中,我似乎得到了这个语法错误。
我正在使用的 gem 是 mysql2 (0.3.18)