M
M
marselabdullin2020-08-07 13:29:26
Oracle
marselabdullin, 2020-08-07 13:29:26

How to translate t-sql query under oracle subd?

I have a task:

You need to configure the automatic conversion of weekly values ​​to monthly values. Sales in transition weeks (part of a week in one month, part in another) must be distributed over calendar days.
In this example, sales for the week ending 03/05/2020 should be distributed as follows: 2 days for February, 5 days for March.

Table with data
Дата 	Сумма 
27.02.2020 	312,00 
05.03.2020 	833,00 
12.03.2020 	225,00 
19.03.2020 	453,00 
26.03.2020 	774,00 
02.04.2020 	719,00 
09.04.2020 	136,00 
16.04.2020 	133,00 
23.04.2020 	157,00 
30.04.2020 	850,00 
07.05.2020 	940,00 
14.05.2020 	933,00 
21.05.2020 	422,00 
28.05.2020 	952,00 
04.06.2020 	136,00 
11.06.2020 	701,00


Table result
Дата мес 	Сумма 
29.фев.20 	550,00 
31.мар.20 	2 560,57 
30.апр.20 	1 481,43 
31.май.20 	3 305,29 
30.июн.20 	778,71 
31.июл.20 	0,00


How to execute a script in ORACLE?
SELECT yy, mm, SUM(part) SUMM 
FROM (
  SELECT 
  *, 
  dateadd(day, -d, date_week) dd, SUMM * 0.2 part, 
  DATEPART (month  , dateadd(day, -d, date_week)) mm, 
  DATEPART (year  , dateadd(day, -d, date_week)) yy
  FROM dbo.Tbl
  CROSS JOIN (
    SELECT 0 d UNION SELECT 1  UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 
    UNION SELECT 5 UNION SELECT 6
  ) days
  WHERE  DATEPART ( weekday  ,  dateadd(day, -d, date_week) ) NOT IN (1, 7)
) daily
GROUP BY yy, mm

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-08-07
@tsklab

Use ORACLE syntax: DatePart , Interval Expressions .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question