如何 运行 多个查询和结果存储在多个 csv 文件中
How to run Multiple Queries and result store in multiple csv files
如何运行 mysql查询并以csv格式输出结果。我知道解决方案应该是这样的:
SELECT col1,col2,col3
FROM my_table
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
但我的问题是,我有大约 15 个查询,我想 运行 所有 15 个查询和结果存储在多个 csv 中 files.currently 对于第一个查询它工作正常并创建 csv file.but 没有为其他人创建 csv queries.Please 帮助 :)
查询 1
SELECT CE.ENTITY_ID 'CUSTOMER ID'
,CE.EMAIL 'CUSTOMER EMAIL ADDRESS'
,CE.CREATED_AT
,CE.UPDATED_AT
,CE.IS_ACTIVE
,CE.STORE_ID
,(SELECT VALUE
FROM CUSTOMER_ENTITY_VARCHAR CEV1
WHERE CEV1.ATTRIBUTE_ID = 1
AND CEV1.ENTITY_ID = CE.ENTITY_ID) AS 'FIRST NAME'
,CEV.VALUE AS 'LAST NAME'
FROM CUSTOMER_ENTITY CE, CUSTOMER_ENTITY_VARCHAR CEV
WHERE CE.ENTITY_ID = CEV.ENTITY_ID
AND CEV.ATTRIBUTE_ID = 2
INTO OUTFILE '$localDrive/DIM_CUSTOMER.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '`'
LINES TERMINATED BY '\n'";
查询2
SELECT LC.LOG_ID
,LC.VISITOR_ID
,LC.CUSTOMER_ID
,LC.LOGIN_AT
,LC.LOGOUT_AT
,LVI.HTTP_REFERER 'REFERRER SOURCE URL'
,LVI.HTTP_USER_AGENT
,LVI.HTTP_ACCEPT_LANGUAGE
,LVI.REMOTE_ADDR
FROM LOG_CUSTOMER LC, LOG_VISITOR_INFO LVI
WHERE LVI.VISITOR_ID = LC.VISITOR_ID
INTO OUTFILE '$localDrive/AGG CUSTOMER LOGIN.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '`'
LINES TERMINATED BY '\n'";
*********************************************已解决** ************************************************
Actual error is the way i execute the query.correct way is given below:
$db->exec($query)
就是这样,它解决了我的问题:
实际错误是我执行query.correct的方式如下:
$db->exec($query);
就是这样,它解决了我的问题:
如何运行 mysql查询并以csv格式输出结果。我知道解决方案应该是这样的:
SELECT col1,col2,col3
FROM my_table
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
但我的问题是,我有大约 15 个查询,我想 运行 所有 15 个查询和结果存储在多个 csv 中 files.currently 对于第一个查询它工作正常并创建 csv file.but 没有为其他人创建 csv queries.Please 帮助 :)
查询 1
SELECT CE.ENTITY_ID 'CUSTOMER ID'
,CE.EMAIL 'CUSTOMER EMAIL ADDRESS'
,CE.CREATED_AT
,CE.UPDATED_AT
,CE.IS_ACTIVE
,CE.STORE_ID
,(SELECT VALUE
FROM CUSTOMER_ENTITY_VARCHAR CEV1
WHERE CEV1.ATTRIBUTE_ID = 1
AND CEV1.ENTITY_ID = CE.ENTITY_ID) AS 'FIRST NAME'
,CEV.VALUE AS 'LAST NAME'
FROM CUSTOMER_ENTITY CE, CUSTOMER_ENTITY_VARCHAR CEV
WHERE CE.ENTITY_ID = CEV.ENTITY_ID
AND CEV.ATTRIBUTE_ID = 2
INTO OUTFILE '$localDrive/DIM_CUSTOMER.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '`'
LINES TERMINATED BY '\n'";
查询2
SELECT LC.LOG_ID
,LC.VISITOR_ID
,LC.CUSTOMER_ID
,LC.LOGIN_AT
,LC.LOGOUT_AT
,LVI.HTTP_REFERER 'REFERRER SOURCE URL'
,LVI.HTTP_USER_AGENT
,LVI.HTTP_ACCEPT_LANGUAGE
,LVI.REMOTE_ADDR
FROM LOG_CUSTOMER LC, LOG_VISITOR_INFO LVI
WHERE LVI.VISITOR_ID = LC.VISITOR_ID
INTO OUTFILE '$localDrive/AGG CUSTOMER LOGIN.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '`'
LINES TERMINATED BY '\n'";
*********************************************已解决** ************************************************
Actual error is the way i execute the query.correct way is given below:
$db->exec($query)
就是这样,它解决了我的问题:
实际错误是我执行query.correct的方式如下:
$db->exec($query);
就是这样,它解决了我的问题: