Home > database >  Sales last week and this week sales at the same time, the rise in sales this year and week
Sales last week and this week sales at the same time, the rise in sales this year and week

Time:10-01

The oracle database table ccs_order
Count (sales)
Id name count cash date
Nokia 1 3792 2017/03/20 11:07:47
2 1 3792 nokia 2017/03/17 11:07:49
3 the nokia 3792 2017/03/19 11:07:50
4 1 3792 nokia 2017/03/18 11:07:52
Dell May 1, 7570 2017/03/18 14:52:23
6 dell 1 5613 2017/03/17 14:52:24

CodePudding user response:

At least give a forward to the results, write some

CodePudding user response:

 select 
The sum (to_char (date, 'ww')='11' then count end) "sales last week,"
The sum (to_char (date, 'ww')='12' then count end) "sales",
The sum (to_char (date, 'yyyy')='2017' then count end) "sales this year,"
(sum (to_char (date, 'ww')='12' then count end) - the sum (to_char (date, 'ww')='11' then count end))/sum (to_char (date, 'ww')='11' then count end) "week rise
"The from ccs_order;

CodePudding user response:

This statement is not very good checked 3 times table
Select sales last week,
This week sales,
This year's sales,
(sales - sales last week)/sales last week week rise
The from (select (select sum (count)
The from ccs_order
Where the date & gt;=trunc (sysdate, 'd') - 6
And the date & lt; Trunc (sysdate, 'd') + 1) sales last week,
(select sum (co without)
The from ccs_order
Where the date & gt;=trunc (sysdate, 'd') + 1
And the date & lt; Trunc (sysdate, 'd') + 8) sales,
(select sum (count)
The from ccs_order
Where the date & gt;=trunc (sysdate, 'YYYY)) this year sales,
The from dual)

CodePudding user response:

 select 
Sum (case when to_char (date, 'ww')='11' then count end) "sales last week,"
The sum (case when to_char (date, 'ww')='12' then count end) "sales",
The sum (case when to_char (date, 'yyyy')='2017' then count end) "sales this year,"
(sum (case when to_char (date, 'ww')='12' then count end) - the sum (case when to_char (date, 'ww')='11' then count end))/sum (case when to_char (date, 'ww')='11' then count end) "week rise
"The from ccs_order;

The second floor forgot to add case the when,,,
  • Related