Home > database >  SQL problem
SQL problem

Time:10-02

A form is as follows:

Date date, urban city, sales staff person, sales sales
.

According to the sales growth in January and February, out of a two-dimensional table, showing the number of sales personnel distribution, the SQL how to write?


10000 the following, 1-50000, more than 50000
Less than 10% of the
10% - 50%.
More than 50%

Thank you very much!

CodePudding user response:

Study the building line column, baidu first, have a question to ask,

CodePudding user response:

reference 1st floor selling fruit net reply:
turn study the building line column, baidu first, have a question to ask,
thanks to mention point, if using the method of case then, I set a select every case inside, meet the growth lines are selected, then back again set a select count, the number of rows selected to satisfy growth?

CodePudding user response:

The create table salesamount (saledate date, city varchar2 (60), saleperson varchar2 (50), the amount number);


Select * FROM (
The select saleperson,
The case when the sum (a.a mount/sumamount) & lt; 0.1 then '10%'
When the sum (a.a mount/sumamount) & gt; 0.5 then '50%'
The else '10% 50% end asum
The case when the sum (a.a mount) & lt; Then 10000 '10000'
When the sum (a.a mount) & gt; 50000 then 'more than 50000'
The else '1-50000' end amo
The from salesamount a
Cross the join (select sum (amount) sumamount from salesamount) b
Group by saleperson) T
Pivot (sum (1) for AMO IN (' 10000 ', '1-50000', '50000')) A
____________________________________________

ASUM '10000' '1-50000 -' 50000 + '
Less than 10% of the 1
10% - 50% 2
3 more than 50% of the 1

CodePudding user response:

Case the when you can, under the specific can baidu, only need to change to your content
  • Related