我很新,可以隨時隨地學習。我試圖操縱SQL代碼來做我想做的事,但沒有完全理解它,所以我遇到了很多問題。在你回答「我不明白你爲什麼這樣做,你應該這樣做」之前,請幫助我找出是否有辦法以我接近它的方式來做到這一點,因爲這需要很長時間才能讓我的大腦發現,但如果真的有更簡單,更好的方法,請詳細解釋給我,否則它會讓我困惑得更多。訪問 - 編寫一個聯合查詢來計算%的內部?
之前,我下面張貼我的全是廢話,我的主要問題是 - **
是有辦法程序通過SQL聯合查詢到其自身內計算百分比?
**就像第一個查詢給我一個總數,下一個查詢根據標準給我提供了新的總數,但需要一個額外的字段告訴我%與第一個查詢相比較。
好了,就到我的廢話希望解釋我想要有效地做到 -
我需要的報告看起來像這樣(編輯:對不起,它看起來並不像它那樣,當我寫後):
病例總數的爭議元共計百分比
所有船艙11
$ 38,812.86所有批准7
$ 27,131.32%(所有保持)APPR的w/o RESUB 5
$ 14,009.27%(所有APPR的)APPR瓦特/ RESUB 2
$ 13,122.05%(所有APPR的)所有下降4
$ 11,681.54%(所有保持)申報的w/o RESUB 3
$ 7,816.14%(所有申報)申報W/RESUB 1
$ 3,865.40%(所有申報的)
我使用的是聯合查詢堅持,我需要到一個報告中的所有查詢。
這裏是完整的SQL代碼(對不起,它太長了)。忽略「select null」片斷,他們是我的bandaid,讓報告分離到我需要的地方。它只是鏈接到一個空表。
> SELECT "All Holds" As Type, Count([Holds Table].[Date email received])
> AS [CountOfDate email received], Sum([Holds Table].[Disputed Dollar
> Amount]) AS [SumOfDisputed Dollar Amount] FROM [Holds Table] WHERE
> ((([Holds Table].[Date email received]) Between [Enter start date:]
> And [Enter end date:]))
>
> UNION ALL
>
> SELECT null as Type, null as [CountOfDate email received], null as
> [SumOfDisputed Dollar Amount] from [extra]
>
> UNION ALL
>
> SELECT "All Approved" As Type, Count([Holds Table].[Date email
> received]) AS [CountOfDate email received], Sum([Holds
> Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar Amount] FROM
> [Holds Table] WHERE ((([Holds Table].[Date email received]) Between
> [Enter start date:] And [Enter end date:])) GROUP BY [Holds
> Table].[SHU Decision] HAVING ((([Holds Table].[SHU Decision])="1"))
>
> UNION ALL
>
> SELECT"Approved without Resubmission" As type, Count([Holds
> Table].[Date email received]) AS [CountOfDate email received],
> Sum([Holds Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar
> Amount] FROM [Holds Table] WHERE ((([Holds Table].[Date email
> received]) Between [Enter start date:] And [Enter end date:])) GROUP
> BY [Holds Table].[SHU Decision], [Holds Table].[Resubmitted?] HAVING
> ((([Holds Table].[SHU Decision])="1") AND (([Holds
> Table].[Resubmitted?])=False))
>
> UNION ALL
>
> SELECT"Approved with Resubmission" As type, Count([Holds Table].[Date
> email received]) AS [CountOfDate email received], Sum([Holds
> Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar Amount] FROM
> [Holds Table] WHERE ((([Holds Table].[Date email received]) Between
> [Enter start date:] And [Enter end date:])) GROUP BY [Holds
> Table].[SHU Decision], [Holds Table].[Resubmitted?] HAVING ((([Holds
> Table].[SHU Decision])="1") AND (([Holds Table].[Resubmitted?])=True))
>
> UNION ALL
>
> Select null as Type, null as [CountOfDate email received], null as
> [SumOfDisputed Dollar Amount] from [extra]
>
> UNION ALL
>
> SELECT "All Declined" As Type, Count([Holds Table].[Date email
> received]) AS [CountOfDate email received], Sum([Holds
> Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar Amount] FROM
> [Holds Table] WHERE ((([Holds Table].[Date email received]) Between
> [Enter start date:] And [Enter end date:])) GROUP BY [Holds
> Table].[SHU Decision] HAVING ((([Holds Table].[SHU Decision])="2"))
>
> UNION ALL
>
> SELECT "Declined without Resubmission" As type, Count([Holds
> Table].[Date email received]) AS [CountOfDate email received],
> Sum([Holds Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar
> Amount] FROM [Holds Table] WHERE ((([Holds Table].[Date email
> received]) Between [Enter start date:] And [Enter end date:])) GROUP
> BY [Holds Table].[SHU Decision], [Holds Table].[Resubmitted?] HAVING
> ((([Holds Table].[SHU Decision])="2") AND (([Holds
> Table].[Resubmitted?])=False))
>
> UNION ALL
>
> SELECT "Declined with Resubmit" As type, Count([Holds Table].[Date
> email received]) AS [CountOfDate email received], Sum([Holds
> Table].[Disputed Dollar Amount]) AS [SumOfDisputed Dollar Amount] FROM
> [Holds Table] WHERE ((([Holds Table].[Date email received]) Between
> [Enter start date:] And [Enter end date:])) GROUP BY [Holds
> Table].[SHU Decision], [Holds Table].[Resubmitted?] HAVING ((([Holds
> Table].[SHU Decision])="2") AND (([Holds
> Table].[Resubmitted?])=True));
唷那麼,這甚至可能還是我剛擰?我確切知道如何在幾秒鐘內計算出Excel中的所有內容,所以我非常沮喪,因爲我無法在Access中看到符合邏輯的事情,而無需在互聯網上搜索我不懂的代碼。除此之外,我希望你能給我提供的任何幫助,或者甚至是「你被搞砸了,也許這樣試試吧」。多謝!
我建議你:刪除所有毫無意義的評論,比如「phew所以,這是可能的還是我只是搞砸了?」,因爲使得dificult理解你。 –
表的定義在哪裏?示例數據? –
你只是在談論你的輸出格式?爲什麼你的代碼不能產生你所期望的? –