mysql - 需要使用mysql查询在前两列中注入(inject)数据

标签 mysql csv

嗨,下面是我的 mysql 查询

select CONCAT(si.ID_PREFIX, si.ID_COUNT) as ID, tmp.NEW_VALUE from ( select ACTIVITY_ID, ISSUE_ID, OLD_VALUE, NEW_VALUE from SCARAB_ACTIVITY where ISSUE_ID in (select ISSUE_ID from SCARAB_ISSUE where MODULE_ID = 656)  and (NEW_VALUE like 'http%') order by ACTIVITY_ID desc) tmp, SCARAB_ISSUE si where tmp.ISSUE_ID = si.ISSUE_ID INTO OUTFILE '/tmp/nxh5102_relatedlinks.csv' FIELDS ENCLOSED BY '' TERMINATED BY ',';

上面的代码会收集数据并将其存储到 csv 文件中,如下所示:

SEE25,https://www.hello.com/sf/tracker/do/viewArtifact/projects.ip_forge/tracker.open_issues/artf31417?_message=1344426489584&returnUrlKey=
SEE355,https://www.google.com/svn/nxh5102/trunk/doc/010 Architecture and Design/MRA3/PRCR doc/NxHSEE355.pptx

我需要在第一行中添加一行,如下所示:

Artifact ID,Related Links
SEE25,https://www.hello.com/sf/tracker/do/viewArtifact/projects.ip_forge/tracker.open_issues/artf31417?_message=1344426489584&returnUrlKey=
SEE355,https://www.google.com/svn/nxh5102/trunk/doc/010 Architecture and Design/MRA3/PRCR doc/NxHSEE355.pptx

我想要这个,这样当我在 Excel 中打开 csv 时,我可以在前两列中看到它们。任何建议都会有帮助。

最佳答案

SELECT 'artifact' id
     , 'related links' new_value
 UNION 
SELECT CONCAT(si.id_prefix, si.id_count)
     , si.new_value 
  FROM scarab_activity sa
  JOIN scarab_issue si
    ON si.issue_id = sa.issue_id    
 WHERE si.module_id = 656
   AND sa.new_value LIKE 'http%' 

关于mysql - 需要使用mysql查询在前两列中注入(inject)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42267446/

相关文章:

java - 将 CSV 文件列中的相似项目分组为主键

csv - 源文件连接(平面文件)-不读取列元数据

python - 在 django 中导出 CSV 文件时出现 405

c# - 如何将任何字符串转换为有效的 CSV 字段?

mySQL:左连接问题

php - 在查询中使用聚合函数需要花费大量时间

mysql - Kohana ORM 按日期选择记录

CSV 文件太大,需要将其拆分为较小的文件

php - 无法在 php 中输出最后一个自动生成的 ID

php - 服务器终端中的 mySQL,需要查看输出