设置参数和源选项

时间:2015-10-01 23:17:55

标签: mysql

我正在尝试运行以下命令:

WITH CTE AS
(
Select 
    rowNum = ROW_NUMBER() OVER(ORDER BY d.CALENDAR_DT_ID),
    d.DAY,
    d.KEY,
    d.BUSINESS_DT,
    d.PREV_DT,
    d.NEXT_DT,
    d.HOLIDAY_IN
FROM CALENDAR_DT d
)
SELECT
    CTE.rowNum,
    CTE.DAY,
    CTE.BUSINESS_DT,
    CTE.KEY,
    CTE.PREV_DT,
    CTE.NEXT_DT,
    prev.KEY As Previous,
    nex.KEY As Next
FROM CTE
LEFT JOIN CTE prev 
ON CTE.PREV_DT = prev.BUSINESS_DT
LEFT JOIN CTE nex 
ON CTE.NEXT_DT = nex.BUSINESS_DT
ORDER BY BUSINESS_DT

它给了我以下错误: 您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获得在源test.sql'附近使用的正确语法。在第1行

但如果我运行以下命令,一切正常:

mysql -u user -pPassword databasename -h server -e "set @yyyymmdd="2015-09-30"; source test.sql";    

我正在使用readline 5.1对于redhat-linux-gnu(x86_64)的#14; mysql Ver 14.12 Distrib 5.0.95 "

2 个答案:

答案 0 :(得分:0)

如果你有sed

,你可以这样做
sed -i '1i SET @yyyymmdd="2015-09-30";' test.sql

然后

mysql -u user -pPassword databasename -h server -e "source test.sql";

答案 1 :(得分:0)

不要错过' -e'的半列。选项

mysql -u user -pPassword databasename -h server -e" set @yyyymmdd =' 2015-09-30' ; source test.sql;&# 34 ;;