example:

select * from (

(select '邮箱','课程编号','状态','名','姓','电话','学员编号','付款类型','信用卡','有效期','人民币',

     '总计','参考','创建时间','更新时间')

union

(select p.email,p.coursecode,p.status,p.firstname,p.lastname,p.phone ,p.stu_number ,p.payment_type,IFNULL(p.creditcard,'-') as creditcard,

IFNULL(p.validdate,'-') as validdate,IFNULL(p.cny,'-') as cny,p.amount,

p.reference,p.createtime,IFNULL(p.updatetime,'-') from t_pay_log p)

) as A

into outfile 'E:\\payment.csv' fields terminated by ',' optionally enclosed by ''' escaped by ''' lines terminated by '\r\n';

有时会出现生成的excel不存在,一般是由于没有权限导出,一般执行以下操作就可以了:
我已经给root用户增设了权限