Home > Mobile >  Total of Various Columns as a Separate Column in Oracle
Total of Various Columns as a Separate Column in Oracle

Time:03-05

Could you help me out with an issue I have in Oracle? Let's say I have a table that tells me about how many items were sold in each month, and looks like so:

Item January February March April
Computer 3 5 2 9
TV 10 12 16 14
Camera 22 25 20 27

What I need in the output is a table that would count the total number of items sold over the period, and would look like this:

Item January February March April Total
Computer 3 5 2 9 19
TV 10 12 16 14 52
Camera 22 25 20 27 94

I am honestly not sure how to do that. Should I use grouping()? Thank you in advance.

CodePudding user response:

You don't need to use grouping at all just try to plus all columns as a new column Total.

SELECT T.*,
       (January   February   March   April) Total
FROM T
  • Related