以前我有這個查詢 -SQL GROUP BY嵌套select語句
SELECT
COUNT(DISTINCT ds.CLIENTID),
COUNT(ds.FACID),
(SUM(ds.NETARREARS) + SUM(ds.TAXARREARS)),
SUM(ds.UNEARNEDINCOME),
SUM(ds.INCOMESUSPENSE) ,
SUM(ds.VATSUSPENSE) ,
SUM(ds.PREPAIDDEPOSIT),
SUM(ds.NETFUTURE) ,
SUM(ds.NETEXPOSURE),
SUM(ds.PROVISION),
SUM(ds.FACILITYSECURITYAMOUNT),
SUM(ds.PROVISIONAMOUNTCFWD)
FROM
DAILY_SUMMARY ds
WHERE
ds.SUMMARY_DATE = :reportDate AND
ds.FACSTS IN('F','L','A') AND
ds.PERSTS = 'N';
但後來我們決定放棄列
ds.UNEARNEDINCOME
(從上第四選擇項)ds.PROVISION
(第10個選擇項目)
因爲我們有替代查詢IES獲取這些,這是 -
SELECT SUM(tcs.DUEAMT) FROM TCRENT tcs WHERE tcs.FACID = ds.FACID AND tcs.DUETYPE = 'INT' AND tcs.DUEDATE > :reportDate
SELECT sum(pup.PROVISIONAMT) FROM PROVISION_UPLOAD pup WHERE pup.PROVISIONDATE < :reportDate AND pup.FACID = ds.FACID
所以最終的查詢 -
SELECT
COUNT(DISTINCT ds.CLIENTID),
COUNT(ds.FACID),
(SUM(ds.NETARREARS) + SUM(ds.TAXARREARS)),
(SELECT SUM(tcs.DUEAMT) FROM TCRENT tcs WHERE tcs.FACID = ds.FACID AND tcs.DUETYPE = 'INT' AND tcs.DUEDATE > :reportDate) AS income,
SUM(ds.INCOMESUSPENSE) ,
SUM(ds.VATSUSPENSE) ,
SUM(ds.PREPAIDDEPOSIT),
SUM(ds.NETFUTURE) ,
SUM(ds.NETEXPOSURE),
(SELECT sum(pup.PROVISIONAMT) FROM PROVISION_UPLOAD pup WHERE pup.PROVISIONDATE < :reportDate AND pup.FACID = ds.FACID) AS prov,
SUM(ds.FACILITYSECURITYAMOUNT),
SUM(ds.PROVISIONAMOUNTCFWD)
FROM
DAILY_SUMMARY ds
WHERE
ds.SUMMARY_DATE = '10-FEB-15' AND
ds.FACSTS IN('F','L','A') AND
ds.PERSTS = 'N';
但現在的問題是整合的2個查詢與主查詢,它給出錯誤 -
非單組功能
表示它需要GROUP BY。我試圖分組,甚至生成的SQL Developer的建議組,但它是不準確的,因爲它是不完整的 -
group by COUNT(DISTINCT, COUNT(ds.FACID), (SUM(ds.NETARREARS), (SELECT,SUM(ds.INCOMESUSPENSE),
SUM(ds.VATSUSPENSE), SUM(ds.PREPAIDDEPOSIT), SUM(ds.NETFUTURE), SUM(ds.NETEXPOSURE), (SELECT
僅供參考 - 如果GROUP BY子句和新2個查詢評論主查詢工作正常。
任何人都可以幫助我嗎?
更新 - 樣品結果截圖
您應該提供樣本數據和期望的結果。 –
您應該提供樣本數據和期望的結果。 –
這仍然是開放的?我永遠不明白爲什麼要在選擇列表中使用選擇... – Thomas