Home > database >  Consult a statement
Consult a statement

Time:09-23

Sales quantity
A 1
3 b
4 c
2 d

Hope to get results is to increase a column, the last is the total sales of all the products, try not to link the subquery

Commodity sales total
A 10 1
3 b 10
C 4 10
2 d 10



CodePudding user response:

 
With a as
(select the 'a' col1, col2 1 from dual
Union all
Select 'b' col1, col2 3 from dual
Union all
Select 'c' col1, col2 4 from dual
Union all
Select the 'd' col1, col2 2 from dual
)
Select col1, col2, res from a, (select sum (col2) res from a)

CodePudding user response:

Select a. *, b.h j from a cross jion (select sum (a. b) as hj from a) b

CodePudding user response:

Directly with the sum () over ()
With a as
(select the 'a' col1, col2 1 from dual
Union all
Select 'b' col1, col2 3 from dual
Union all
Select 'c' col1, col2 4 from dual
Union all
Select the 'd' col1, col2 2 from dual
)
Select col1, col2, sum (col2) over () from a

CodePudding user response:

Figure 1 is a code, figure 2 is the query results,

CodePudding user response:

My pictures, zha is missing

CodePudding user response:

With temp as
(select the 'a' goods, l nums
The from dual
Union all
Select 'b' goods, 2 nums
The from dual
Union all
Select the 'c' goods, 3 nums
The from dual
Union all
Select the 'd' goods, 4 nums
The from dual)
The select goods commodity
Nums sales quantity
Combined the Sum (nums) over (order by1)
The from temp.
  • Related