您能将多个oracle sql查询的结果放入一个csv文件中吗?

bq9c1y66  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(189)

我有一个用php创建的网页,有七个链接-每个链接下载一个.csv文件,其中包含来自不同oracle sql查询的结果。用户想知道它们是否都可以在一个.csv文件中,并且每个查询的结果都在同一工作簿中各自的工作表中。我假设这是不可能的,但我不想说不,至少没有研究它。我试着在网上搜索答案,但没有找到任何接近的答案。
举个例子,这里有两个当前使用的查询。他们希望每个查询的结果都位于同一工作簿/csv文件中自己的工作表上。

SELECT StoreNbr, 
SUM(CASE WHEN(OrigFormMethod = 'FORMULA BK') THEN Gallons ELSE 0 END) AS Formula_Bk_Gals,
SUM(CASE WHEN(OrigFormMethod = 'MANUAL') THEN Gallons ELSE 0 END) AS Manual_Gals,
SUM(CASE WHEN(OrigFormMethod = 'PCT OF SC') THEN Gallons ELSE 0 END) AS Pct_Of_Sc_Gals,
SUM(CASE WHEN(OrigFormMethod = 'MODIFIED PCT OF SC') THEN Gallons ELSE 0 END) AS Modified_Pct_Of_Sc_Gals,
SUM(CASE WHEN(OrigFormMethod = 'SHER-COLOR') THEN Gallons ELSE 0 END) AS SherColor_Gals,
SUM(CASE WHEN(OrigFormMethod = 'MODIFIED SHER-COLOR') THEN Gallons ELSE 0 END) AS Modified_SherColor_Gals,
SUM(CASE WHEN(OrigFormMethod = 'MODIFIED FORMULA BK') THEN Gallons ELSE 0 END) AS Modified_Formula_Bk,
SUM(CASE WHEN(OrigFormMethod = 'PCT OF FB') THEN Gallons ELSE 0 END) AS Pct_Of_Formula_Bk, 
SUM(CASE WHEN(OrigFormMethod = 'MODIFIED PCT OF FB') THEN Gallons ELSE 0 END) AS Modified_Pct_Of_Formula_Bk
FROM MQ_CDS_NETTRAN
WHERE ((CostCenter = '701104' AND LastTranDate >= DATE '2020-03-10') 
OR (CostCenter = '701109' AND LastTranDate >= DATE '2020-03-04')
OR (CostCenter = '701257' AND LastTranDate >= DATE '2020-03-12'))
AND ClrntSys = 'GIC'
GROUP BY StoreNbr
ORDER BY StoreNbr;

SELECT 
StoreNbr, 
TRUNC(LastTranDate, 'DAY') AS Week_Beginning,
SUM(CASE WHEN(ClrntSys IN ('844', '84448')) THEN Gallons ELSE 0 END) AS Gallons_844,
SUM(CASE WHEN(ClrntSys ='GIC') THEN Gallons ELSE 0 END) AS Gallons_GIC,
SUM(CASE WHEN(ClrntSys IN ('844', '84448', 'GIC')) THEN Gallons ELSE 0 END) AS Total_Gallons,
CONCAT(CAST((SUM(CASE WHEN(ClrntSys ='GIC') THEN Gallons ELSE 0 END) /
SUM(CASE WHEN(ClrntSys IN ('844', '84448', 'GIC')) THEN Gallons ELSE NULL END)) AS DECIMAL (7,2)) * 100, '%') AS Percent_GIC
FROM MQ_CDS_NETTRAN
WHERE ((CostCenter = '701104' AND LastTranDate >= DATE '2020-03-10')
OR (CostCenter = '701109' AND LastTranDate >= DATE '2020-03-04')
OR (CostCenter = '701257' AND LastTranDate >= DATE '2020-03-12'))
GROUP BY ROLLUP(StoreNbr), TRUNC(LastTranDate, 'DAY')
ORDER BY TRUNC(LastTranDate, 'DAY'), StoreNbr;

这可能吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题