I have a question
target table
str_week_day end_week_day age_id usage_ratio eq_type
------------ ------------ ------ ----------- -------
11-Jul-10 17-Jul-10 1.00 0.5 RECEIVER
11-Jul-10 17-Jul-10 2.00 0.5 HUB
18-Jul-10 24-jul-10 1.00 0.5 RECEIVER
18-Jul-10 24-jul-10 2.00 0.5 HUB
.......
......
and so on
source table
Start_date End_Date age_id eq_type
---------- -------- ------ -------
13-Jul-10 30-Jul-10 1.00 RECEIVER
15-Jul-10 25-Jul-10 2.00 HUB
ill give the sample
source_data
DIM_PANELIST_ID E E_SERIAL_NMBR DIM_PANEL_ID AGE_ID BEGIN_DATE END_DATE P_BEGIN_DATE INSERT_TS UPDATE_TS
--------------- - ------------- ------------ ---------- ---------- ---------- ------------ --------------------------------------------------------------------------- ----------------------------------------------------
1 M 172241 12 2 1616 1742 977 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
1 R 812890 12 2 1616 1742 977 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
2 M 154918 12 3 1560 1639 894 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
2 M 275351 12 3 1483 1560 894 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
3 M 155758 12 3 1560 1639 894 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
4 M 240087 12 4 1508 1557 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
4 M 151575 12 4 1557 1601 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
4 M 116520 12 4 1602 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
5 M 158929 12 4 1576 1588 868 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
6 R 812346 12 4 1621 1676 1112 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
6 M 170735 12 4 1621 1676 1112 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
7 M 279409 12 4 1662 1686 944 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
7 M 272720 12 4 1508 1661 944 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 M 194139 12 5 1712 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 M 279839 12 5 1484 1511 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 R 319711 12 5 1512 1620 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 R 812067 12 5 1620 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 M 274505 12 5 1512 1620 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
8 M 171353 12 5 1620 1709 1155 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
9 M 173784 12 5 1617 1315 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
9 R 814566 12 5 1617 1315 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
10 M 154363 12 5 1557 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
11 M 145473 12 5 1558 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
11 R 322260 12 5 1558 1324 13-JUL-10 09.07.35.000000 PM 13-JUL-10 09.07.35.000000 PM
12 M 158807 12 5 1576 1588 868 13-JUL-10 09.07.35.000000 PM 13-JUL-10
expected_target_data
STR_WK_DAY END_WK_DAY EQ_TYPE USAGE_RATIO
4-Jan-09 10-Jan-09 R 0.5
4-Jan-09 10-Jan-09 M 0.5
11-Jan-09 17-Jan-09 M 1
18-Jan-09 24-Jan-09 M 1
18-Jan-09 24-Jan-09 M 1
18-Jan-09 24-Jan-09 M 1
the data in the target is not accurate except the date's
I want to populate the target table I don’t know how to populate it The couple of scripts I have tried are
Mfrp1 table is the source table
select (select count(*)
from mfrp1
where aid=a.aid )/(select count(*)
from mfrp1) as ratio
, a.aid as ageid
, (case when a.m>a.r then 'M' else 'R'end) as eq_type
from (select aid
, sum(case when eq_type='M'then 1 else 0 end) as "M",
sum(case when eq_type='R'then 1 else 0 end) as "R"
from mfrp1 group by aid) a;