How to calculate arithmetic expression of column members database table?

Viewed 399

I have result from this query

SELECT
    myTable.Branch AS Branch,
    myTable.Quarter AS Quarter,
    SUM(myTable.Sales) AS Sales
FROM
    myTable
GROUP BY
    myTable.Branch,
    myTable.Quarter

Branch  Quarter Sales
B1      Q1      17
B1      Q2      7
B1      Q3      1
B1      Q4      8
B1      Q5      12
B2      Q1      8
B2      Q2      5
B2      Q3      2
B2      Q4      14
B2      Q5      17

Now I want to get calculate member lets say Q1-Q3 then result should look like

Branch  Quarter     Sales
B1      Q1          17
B1      Q2          7
B1      Q3          1
B1      Q4          8
B1      Q5          12
B1      Q1-Q3       16
B2      Q1          8
B2      Q2          5
B2      Q3          2
B2      Q4          14
B2      Q5          17
B2      Q1-Q3       6

Expression can be any valid arithmetic expression like (Q1+Q2-Q3)*2

3 Answers
Related