我在mysql中创建了一个存储过程
DELIMITER //
CREATE PROCEDURE simpleproc ()
BEGIN
SELECT YEAR(dtm),
WEEK(dtm),
b.x_title,
COUNT(b.x_id)
INTO OUTFILE '/appdata/reports01/result.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM tbla a
JOIN tblb b ON b.x_id = a.x_id
WHERE plan_grp_id IN (10031, 10034)
AND dtm > '20110101'
GROUP BY YEAR(dtm), WEEK(dtm), a.x_id;
END //
delimiter ;
我需要做两件事
INTO OUTFILE '/appdata/reports01/result.csv'
必须像“INTO OUTFILE”/appdata/reports01/result-current-timestamp.csv'此:
SELECT CURDATE() + 0
...为我提供格式'20110101',但我不能在dtm > CURDATE() + 0
答案 0 :(得分:1)
使用变量。
DECLARE outfile_name varchar(300);
获取当前时间戳并将其附加到字符串的剩余部分。 使用INTO关键字将SELECT语句的输出转换为变量。 使用CONCAT()来连接2个字符串。