Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL:正在努力编写SQL脚本_Sql_Postgresql - Fatal编程技术网

SQL:正在努力编写SQL脚本

SQL:正在努力编写SQL脚本,sql,postgresql,Sql,Postgresql,SQL:我正在尝试编写一个脚本来运行整个月的每日事务细节 我想创建3个变量: month , begin_date , end_date , 这样,在下个月运行脚本时,我只需更新这些变量一次,而不是更新每一行 理想情况下,我希望脚本为特定客户机执行特定查询 `month = 'April' begin_date ='2018-04-01' end_date = '2018-04-30' SELECT date,client,price FROM clientdb WHERE date &g

SQL:我正在尝试编写一个脚本来运行整个月的每日事务细节

我想创建3个变量:

month ,
begin_date ,
end_date ,
这样,在下个月运行脚本时,我只需更新这些变量一次,而不是更新每一行

理想情况下,我希望脚本为特定客户机执行特定查询

`month = 'April'
begin_date ='2018-04-01'
end_date = '2018-04-30'


SELECT date,client,price
FROM clientdb
WHERE date >= begin_date and date <= end_date and client='xxxx' `
`month='April'
开始日期=“2018-04-01”
结束日期='2018-04-30'
选择日期、客户、价格
来自clientdb

其中date>=begin\u date and date=begin\u date and date取决于脚本的运行方式。假设这是Linux,您可以使用date函数为SQL脚本提供数据。大概是这样的:

/myReportExport.sh `date -d "-1 months" +%Y-%m` `date -d "-2 months" +%Y-%m` `date -d "-1 months" +%m/01/%Y` > myreport.csv

请提供更多有关您环境的信息,我可能会提供更多帮助。不过,没有内置的Postgres to Excel函数。这将需要第三方工具或使用Excel ODBC来执行查询

PostgreSQL对MS Excel一无所知,但两者都可以处理CSV/TSV格式。看这张照片
/myReportExport.sh `date -d "-1 months" +%Y-%m` `date -d "-2 months" +%Y-%m` `date -d "-1 months" +%m/01/%Y` > myreport.csv