由于某种原因,我需要导出查询结果并将csv
文件保存在mysql中。
我写的是:
SELECT orders.user_id, orders.order_id, members.name, members.family,
orders.agent_id, CONCAT(m.name, ' ', m.family) AS agent_name
FROM orders
JOIN members
ON members.username=orders.user_id
JOIN members m
ON orders.agent_id=m.username
WHERE order_status=4 and pay_method='verbalPayment'
AND agent_id is not NULL
AND order_time BETWEEN 1559935800 AND 1560596861
INTO OUTFILE 'weekly_orders.csv' FIELDS TERMINATED BY ',';
但是当我运行此查询时,出现此错误:
静态分析:
在分析过程中发现1个错误。
子句的意外排序。 (在“ FROM”位置131附近)
我不知道问题是什么,我该如何解决。
答案 0 :(得分:1)
错误进入子句位置
pClass<float> pfloat{static_cast<pClass<float>>(pInt)};
答案 1 :(得分:1)
您需要将INTO OUTFILE 'weekly_orders.csv' FIELDS TERMINATED BY ','
放在FROM
子句的前面
例如
....INTO OUTFILE 'weekly_orders.csv' FIELDS TERMINATED BY ','
FROM orders ....
答案 2 :(得分:1)
很明显,问题在于INTO
跟在SELECT
之后。我建议将查询写为:
SELECT o.user_id, o.order_id, mu.name, mu.family,
o.agent_id, CONCAT_WS(' ', ma.name, ma.family) AS agent_name
INTO OUTFILE 'weekly_orders.csv' FIELDS TERMINATED BY ','
FROM orders o JOIN
members mu
ON mu.username = o.user_id JOIN
members ma
ON o.agent_id = ma.username
WHERE o.order_status = 4 AND
o.pay_method = 'verbalPayment' AND
o.order_time BETWEEN 1559935800 AND 1560596861 ;
注意:
agent_id is not NULL
是多余的。 JOIN
会解决这个问题。mu
代表“作为用户的成员”和ma
代表“作为代理的成员”更容易理解。CONCAT_WS()
可以工作,即使其中一个名字是NULL
。