Assuming your table is called [t]
, and that the Value
column has been called Val
(Value
is a reserved word and complicates things), you can create a view (query) with the following SQL definition:
SELECT
t0.CPTY, t0.Industry, t0.Val * 100.0 /
(SELECT sum(t1.Val) FROM t AS t1
WHERE t1.CPTY = t0.CPTY) AS PerCentIndustryPerCpty
FROM
t AS t0;
You can make it using the "SQL view" instead of the graphical designer for views (querys).
You get this result:
If you don't feel comfortable with the SQL view, this can also be done within the GUI, in two steps:
- Create a Query named
TotalsPerCPTY
with a column namedTotalValPerCPTY
that has theSUM
s ofVal
GROUPed BY
CPTY
, as shown in the following image:
- Create the
ViePerCents
Query by joining thet
table together with theTotalsPerCPTY
view, using theCPTY
column, with one computed column that computesVal / TotalValPerCPTY * 100.0
: