Reputation:
I have Sales throughout the Year and I want to know on which weekdays it was the busiest based on the sales of that day.
I am pretty new to SQL so..
For Example, it looks like this:
Date Sales CompanyID
14.10.2020 20 12
14.10.2020 10 2
15.10.2020 15 19
15.10.2020 6 4
And I want it to look like this:
Weekday Sales
Wednesday 30
Thursday 21
I think I have to use the sum() function on sales and order it by weekdays with date ?
Upvotes: 0
Views: 150
Reputation: 143003
Use TO_CHAR
with appropriate format mask. For example (in which sample data is in lines #1 - 6; query you need begins at line #7):
SQL> with test (datum, sales, companyid) as
2 (select date '2020-10-14', 20, 12 from dual union all
3 select date '2020-10-14', 10, 2 from dual union all
4 select date '2020-10-15', 15, 19 from dual union all
5 select date '2020-10-15', 6, 4 from dual
6 )
7 select to_char(datum, 'fmDay') day,
8 sum(sales) sales
9 from test
10 group by to_char(datum, 'fmDay');
DAY SALES
--------- ----------
Wednesday 30
Thursday 21
SQL>
Upvotes: 1