Skip to main content
added 662 characters in body
Source Link
joanolo
  • 13.6k
  • 8
  • 39
  • 66

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:

ViewPerCents


If you don't feel comfortable with the SQL view, this can also be done within the GUI, in two steps:

  1. Create a Query named TotalsPerCPTY with a column named TotalValPerCPTY that has the SUMs of Val GROUPed BY CPTY, as shown in the following image:

TotalsPerCPTY Query

  1. Create the ViePerCents Query by joining the t table together with the TotalsPerCPTY view, using the CPTY column, with one computed column that computes Val / TotalValPerCPTY * 100.0:

Final query

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:

ViewPerCents

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:

ViewPerCents


If you don't feel comfortable with the SQL view, this can also be done within the GUI, in two steps:

  1. Create a Query named TotalsPerCPTY with a column named TotalValPerCPTY that has the SUMs of Val GROUPed BY CPTY, as shown in the following image:

TotalsPerCPTY Query

  1. Create the ViePerCents Query by joining the t table together with the TotalsPerCPTY view, using the CPTY column, with one computed column that computes Val / TotalValPerCPTY * 100.0:

Final query

Source Link
joanolo
  • 13.6k
  • 8
  • 39
  • 66

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:

ViewPerCents