0% found this document useful (0 votes)
99 views

Queries

The document contains several SQL queries that analyze and summarize charge data from tables including charge, normalized_event, and service_history. The queries filter for specific date ranges, accounts, MSISDNs, event types and return fields like charge date, amount, calling and called parties, duration and other general fields to analyze phone call charges.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Queries

The document contains several SQL queries that analyze and summarize charge data from tables including charge, normalized_event, and service_history. The queries filter for specific date ranges, accounts, MSISDNs, event types and return fields like charge date, amount, calling and called parties, duration and other general fields to analyze phone call charges.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Updated Charge table:

select c.last_modified, c.charge_start_date, c.invoice_txt, c.charge,


ne.a_party_id, ne.b_party_id, c.general_3, c.general_4, c.general_5,
c.general_6, c.general_7, c.general_8, c.general_9 , ne.general_20
from charge c, normalised_event ne
where c.service_id in (select sh.service_id from service_history sh
where sh.service_name = '0831280243' --MSISDN
and sysdate between sh.effective_start_date and sh.effective_end_date)
and c.charge_start_date >= to_date('18/01/2014 00:00:00','DD/MM/YYYY
hh24:mi:ss') --Charges From
and c.charge_start_date < to_date('18/01/2014 23:59:59','DD/MM/YYYY
hh24:mi:ss') --Charges Till
--and c.invoice_txt like '%Mobile%' --Event Type
and c.normalised_event_id = ne.normalised_event_id
--and c.charge <> '0' --Zero Rated charges
--and c.invoice_id = '694336445'
order by c.charge_start_date

select (select a.account_name from account a where a.account_id =


c.ACCOUNT_ID) "Account Name",
decode(c.SERVICE_ID,null,null,
(select sh.SERVICE_NAME || ' / ' || sh.NETWORK_NAME
from service_history sh
where sh.SERVICE_ID = c.SERVICE_ID
and sh.SERVICE_STATUS_CODE = 3 -- 3 = Active ; 9 =
Cancelled
and c.CHARGE_START_DATE between sh.EFFECTIVE_START_DATE
and sh.EFFECTIVE_END_DATE)) "Service Name / IMSI",
ne.A_PARTY_NETWORK_ID "IMSI (NE)",
c.CHARGE_START_DATE,
c.INVOICE_TXT,
c.CHARGE,
nvl(ne.DURATION,ne.VOLUME) "Duration",
c.GENERAL_3 "GENERAL_3 (FU)",
(select ct.code_label || ' : ' || ct.description from reference_code
ct where ct.reference_type_id = 4100110 and ct.code_label = c.GENERAL_1)
"GENERAL_1",
(select et.REFERENCE_CODE || ' : ' || et.ABBREVIATION from
reference_code et where et.REFERENCE_TYPE_ID = 4100006 and et.REFERENCE_CODE
= ne.EVENT_TYPE_CODE) "Event Type Code",
(select est.REFERENCE_CODE || ' : ' || est.ABBREVIATION from
reference_code est where est.REFERENCE_TYPE_ID = 4100057 and
est.REFERENCE_CODE = ne.EVENT_SUB_TYPE_CODE) "Event Sub Type Code",
ne.NORMALISED_EVENT_ID,
ne.A_PARTY_ID "CALLING PARTY",
ne.B_PARTY_ID "CALLED PARTY",
ne.GENERAL_20 "GENERAL_20 (SESSION ID)",
ne.B_PARTY_NAME,
ne.EVENT_SOURCE,
c.GENERAL_7 "GENERAL_7 (NU)",
c.LAST_MODIFIED
from charge c,
normalised_event ne
where c.CHARGE_START_DATE between to_date('28-06-2018 00:00:00','dd-mm-yyyy
hh24:mi:ss') and to_date('28-06-2018 23:59:59','dd-mm-yyyy hh24:mi:ss')
and c.NORMALISED_EVENT_ID = ne.NORMALISED_EVENT_ID
--and c.INVOICE_ID in ()
--and c.ACCOUNT_ID in (select a.ACCOUNT_ID from account a where
a.ACCOUNT_NAME = '8212995305')
and c.SERVICE_ID in (select sh.SERVICE_ID from service_history sh where
sh.SERVICE_TYPE_ID = 4100005 and sh.SERVICE_NAME = ' 0830482443') -- 4100005
= Voice Service Type
--and c.INVOICE_TXT in ('Mobile Internet')
--and c.INVOICE_TXT not in ('Standard tax rate')
--and ne.A_PARTY_ID in ('00447810206074')
--and ne.B_PARTY_ID in ('00447782333123')
--and ne.GENERAL_20 = ''
order by c.CHARGE_START_DATE desc ;

Query to find charge configured in DA against event_type, event_sub_type and Package :


-- Inputs: Package Name, Companion Product Name, Event Type and Event Sub
Type
-- Output: Refere RESULT4_VALUE for the configured rate

select dah.TABLE_NAME, dah.DESCRIPTION, daa.SEQNR,


p1.PRODUCT_NAME "Package",p2.PRODUCT_NAME "Product", et.abbreviation
"Event Type", est.abbreviation "Event Subtype", tb.abbreviation "Time Band",
daa.INDEX6_VALUE, daa.INDEX7_VALUE, daa.INDEX8_VALUE,
daa.INDEX9_VALUE, daa.INDEX10_VALUE,
daa.RESULT1_VALUE, daa.RESULT2_VALUE, daa.RESULT3_VALUE,
daa.RESULT4_VALUE, daa.RESULT5_VALUE,
daa.RESULT6_VALUE, daa.RESULT7_VALUE, daa.RESULT8_VALUE,
daa.RESULT9_VALUE, daa.RESULT10_VALUE
from derived_attribute_array daa,
derived_attribute_history dah,
(SELECT product_id, product_name, SUBSTR(description, 1, 80)
FROM product_history
WHERE companion_ind_code = 0
AND sysdate between effective_start_date and effective_end_date
UNION
SELECT reference_code, abbreviation, substr(description,1,80)
FROM reference_code
WHERE reference_type_id =
(SELECT reference_type_id
FROM reference_type
WHERE type_label = 'H3G_CMN_WC_NA_EVENT_TYPES')
and reference_code = -1
ORDER BY 2) p1,
(SELECT product_id, product_name, SUBSTR(description, 1, 80)
FROM product_history
WHERE companion_ind_code = 0
AND sysdate between effective_start_date and effective_end_date
UNION
SELECT reference_code, abbreviation, substr(description,1,80)
FROM reference_code
WHERE reference_type_id =
(SELECT reference_type_id
FROM reference_type
WHERE type_label = 'H3G_CMN_WC_NA_EVENT_TYPES')
and reference_code = -1
ORDER BY 2) p2,
reference_code et,
reference_code est,
reference_code tb
where sysdate between daa.EFFECTIVE_START_DATE and daa.EFFECTIVE_END_DATE
and sysdate between dah.EFFECTIVE_START_DATE and dah.EFFECTIVE_END_DATE
and dah.DERIVED_ATTRIBUTE_ID = daa.DERIVED_ATTRIBUTE_ID
and daa.DERIVED_ATTRIBUTE_ID in
(4100000,4100001,4100079,4100146,4100152,4100153,4100154,4100155,4200260,4200
551,
11003708,11001046,4200302,440
0143,4100303,11001146,4100166,4200307,11000844,4200296,
4100059,11001908,11001870,110
01886,4200301,4200610,4200549,4200550,4200697,4200261,4100062,
4100063,4400044,4100119,41001
50,11003608,11002449,4100070,4100076,4100151,4200471,4100184,
4100192,4100443,4200740,42007
81,4200800,4200823,4100215,4100343,4100213,4100183,4100182,
4100212,11002808,4100042,4200
297,4200322,4100130,4100214,11002548,4100208,4100041,8000023,
4200305,4100075)
and daa.INDEX1_VALUE = p1.PRODUCT_ID
and et.reference_type_id = 4100006 and et.reference_code = daa.INDEX3_VALUE
and est.reference_type_id = 4100057 and est.reference_code = daa.INDEX4_VALUE
and tb.reference_type_id = 4100000 and tb.reference_code = daa.INDEX5_VALUE
and daa.INDEX2_VALUE = p2.PRODUCT_ID
and (p1.PRODUCT_NAME = 'RoI CCS BAS_Classic Flex Max 350 Package' or
daa.INDEX1_VALUE = '-1') -- Change Package Name
and (p2.PRODUCT_NAME = '' or daa.INDEX2_VALUE = '-1') -- Change Companion
Product Name
and daa.INDEX3_VALUE = '210000' -- Change Event Type
and daa.INDEX4_VALUE = '201203' -- Change Event Sub Type

Charge table analysis:

SELECT ne.b_party_ton_code,ne.c_party_route,c.charge_id,
ne.full_path,c.charge,to_char(c.charge_start_date, 'DD-MON-YYYY hh:mm:ss') charge_start_date,
ne.charge_start_date,ne.last_modified charge_end_date,c.invoice_txt, c.general_1, c.general_3,
ne.a_party_network_id,ne.b_party_id, ne.a_party_id,ne.general_2,ne.general_3 negeneral_3,
ne.general_20, ne.duration, ne.normalised_event_id,
nef.normalised_event_file_id, nef.filename, nef.process_start_date, nef.process_end_date,
nef.event_source
FROM charge c, normalised_event ne, normalised_event_file nef
WHERE c.account_id in ( select account_id from account where account_name = '8216196132') -- RA
this is account_id from account
--and c.invoice_txt = 'Usage Message Event' --'Voice minutes'
AND c.invoice_txt = 'National and International Voice Calls'
AND c.charge_start_date between to_date('01/01/2013 00:00:00','dd/mm/yyyy hh24:mi:ss') and
to_date('31/01/2013 23:59:59','dd/mm/yyyy hh24:mi:ss')
-- >=trunc(sysdate -60)
--and c.general_3='0,[ ],[ ],[ ]|0,[ ],[ ],[ ]|250,[ 263068967.20110625 ],[ 250 ],[ 39 ]'
--and c.general_3 like '%263068967%'
AND c.normalised_event_id = ne.normalised_event_id
AND tariff_id != '11000001'
--and b_party_ton_code
--and ne.b_party_id = '00447906902565'
--and c.charge != '0.000000'
--and charge_id=101781593493
AND nef.normalised_event_file_id = ne.normalised_event_file_id
ORDER BY c.charge_start_date

Another query for charge table anaylsis

select a.ACCOUNT_NAME "ACCOUNT NUMBER",


sh.SERVICE_NAME "MSISDN",
sh.NETWORK_NAME "IMSI",
c.CHARGE_START_DATE,
c.INVOICE_TXT,
c.CHARGE,
ne.DURATION,
srd.DELTA_VALUE,
ne.NORMALISED_EVENT_ID,
ne.A_PARTY_ID "CALLING PARTY",
ne.B_PARTY_ID "CALLED PARTY",
ne.GENERAL_20 "SESSION ID"
from service_history sh,
account a,
charge c,
normalised_event ne,
subtotal_rating_delta srd
where sh.CUSTOMER_NODE_ID = a.CUSTOMER_NODE_ID
and sh.SERVICE_STATUS_CODE = 9
and a.ACCOUNT_ID = c.ACCOUNT_ID
and length(a.ACCOUNT_NAME) = 10
and ne.NORMALISED_EVENT_ID = c.NORMALISED_EVENT_ID
and srd.NORMALISED_EVENT_ID = ne.NORMALISED_EVENT_ID
and sysdate between sh.EFFECTIVE_START_DATE and sh.EFFECTIVE_END_DATE
--and sh.SERVICE_NAME in ('0851703565')
and a.ACCOUNT_NAME in ('8214401369')
--and ne.A_PARTY_ID in ('00447810206074')
--and ne.B_PARTY_ID in ('00447454704274')
--and c.INVOICE_TXT in ('Special Voice Calls')
--and ne.GENERAL_20 = '100447782000003===EABAOAE2ANvIDFGOuu'
and c.CHARGE_START_DATE between to_date('05-09-2013 00:00:00','dd-mm-yyyy
hh24:mi:ss') and to_date('05-09-2013 23:59:59','dd-mm-yyyy hh24:mi:ss')
order by c.CHARGE_START_DATE desc

--Query to monitor:
select * from batch_processes order by 1 desc

--Query to check time taken by process step on previous day:


select bpn.PROCESS_STEP,
bpn.DESCRIPTION,
bpn.STATUS,
bpn.ERROR,
bpn.STEP_TIMESTAMP,
bpn.END_STEP_TIMESTAMP,
bpo.STEP_TIMESTAMP "OLD_STEP_TIMESTAMP",
bpo.END_STEP_TIMESTAMP "OLD_END_STEP_TIMESTAMP"
from batch_processes bpo,
batch_processes bpn
where bpo.PROCESS_STEP = bpn.PROCESS_STEP
and bpo.DESCRIPTION = bpn.DESCRIPTION
and bpo.STATUS = 'OK'
and trunc(bpo.STEP_TIMESTAMP) = trunc(sysdate -1)
and trunc(bpn.STEP_TIMESTAMP) = trunc(sysdate)
order by bpn.STEP_TIMESTAMP desc

1) Query to check the charged event in database. Put MSISDN in service_name, invoice_txt is the
charged event like sms, call etc

select c.last_modified, c.charge_start_date, c.invoice_txt, c.charge,


ne.a_party_id, ne.b_party_id, c.general_3, c.general_4, c.general_5,
c.general_6, c.general_7, c.general_8, c.general_9 , ne.general_20
from charge c, normalised_event ne
where c.service_id in (select sh.service_id from service_history sh
where sh.service_name = '0831280243' --MSISDN
and sysdate between sh.effective_start_date and sh.effective_end_date)
and c.charge_start_date >= to_date('18/01/2014 00:00:00','DD/MM/YYYY
hh24:mi:ss') --Charges From
and c.charge_start_date < to_date('18/01/2014 23:59:59','DD/MM/YYYY
hh24:mi:ss') --Charges Till
--and c.invoice_txt like '%Mobile%' --Event Type
and c.normalised_event_id = ne.normalised_event_id
--and c.charge <> '0' --Zero Rated charges
--and c.invoice_id = '694336445'
order by c.charge_start_date

select (select a.account_name from account a where a.account_id =


c.ACCOUNT_ID) "Account Name",
decode(c.SERVICE_ID,null,null,
(select sh.SERVICE_NAME || ' / ' || sh.NETWORK_NAME
from service_history sh
where sh.SERVICE_ID = c.SERVICE_ID
and sh.SERVICE_STATUS_CODE = 3 -- 3 = Active ; 9 =
Cancelled
and c.CHARGE_START_DATE between sh.EFFECTIVE_START_DATE
and sh.EFFECTIVE_END_DATE)) "Service Name / IMSI",
ne.A_PARTY_NETWORK_ID "IMSI (NE)",
c.CHARGE_START_DATE,
c.INVOICE_TXT,
c.CHARGE,
nvl(ne.DURATION,ne.VOLUME) "Duration",
c.GENERAL_3 "GENERAL_3 (FU)",
(select ct.code_label || ' : ' || ct.description from reference_code
ct where ct.reference_type_id = 4100110 and ct.code_label = c.GENERAL_1)
"GENERAL_1",
(select et.REFERENCE_CODE || ' : ' || et.ABBREVIATION from
reference_code et where et.REFERENCE_TYPE_ID = 4100006 and et.REFERENCE_CODE
= ne.EVENT_TYPE_CODE) "Event Type Code",
(select est.REFERENCE_CODE || ' : ' || est.ABBREVIATION from
reference_code est where est.REFERENCE_TYPE_ID = 4100057 and
est.REFERENCE_CODE = ne.EVENT_SUB_TYPE_CODE) "Event Sub Type Code",
ne.NORMALISED_EVENT_ID,
ne.A_PARTY_ID "CALLING PARTY",
ne.B_PARTY_ID "CALLED PARTY",
ne.GENERAL_20 "GENERAL_20 (SESSION ID)",
ne.B_PARTY_NAME,
ne.EVENT_SOURCE,
c.GENERAL_7 "GENERAL_7 (NU)"
from charge c,
normalised_event ne
where c.CHARGE_START_DATE between to_date('01-11-2016 00:00:00','dd-mm-yyyy
hh24:mi:ss') and to_date('05-11-2016 23:59:59','dd-mm-yyyy hh24:mi:ss')
and c.NORMALISED_EVENT_ID = ne.NORMALISED_EVENT_ID
--and c.INVOICE_ID in ()
--and c.ACCOUNT_ID in (select a.ACCOUNT_ID from account a where
a.ACCOUNT_NAME = '8212995305')
and c.SERVICE_ID in (select sh.SERVICE_ID from service_history sh where
sh.SERVICE_TYPE_ID = 4100005 and sh.SERVICE_NAME = '0868570580') -- 4100005
= Voice Service Type
--and c.INVOICE_TXT in ('Mobile Internet')
--and c.INVOICE_TXT not in ('Standard tax rate')
--and ne.A_PARTY_ID in ('00447810206074')
--and ne.B_PARTY_ID in ('00447782333123')
--and ne.GENERAL_20 = ''
order by c.CHARGE_START_DATE desc

2) Free unit usage: do alt+enter selecting BAN in single view for


customer_node_id

select srv.key_value,srv.start_date,
srv.end_date,srv.event_start_date,srv.event_end_date, srv.value as Consumed,
sda.result2_value as Allocated,sda.result2_value-srv.value left
from subtotal_rating_value srv, service_da_array sda, service_history sh
where srv.customer_node_id = 35779196 and srv.key_value = '318647487'
and sda.index1_value = srv.key_value
and sh.customer_node_id = srv.customer_node_id
and sh.service_id = sda.service_id
and sysdate between sh.effective_start_date and sh.effective_end_date
and sysdate between sda.effective_start_date and sda.effective_end_date
order by srv.key_value,event_start_date
select sh.SERVICE_NAME,
sda.INDEX1_VALUE "Free Unit Alloc Id",
rc1.abbreviation || ' / ' || rc2.abbreviation || ' / ' ||
rc3.abbreviation "Category / Type / Repeat",
sda.RESULT2_VALUE "Initial Free Units",
sda.RESULT3_VALUE "Free Unit Start Date",
sda.RESULT4_VALUE "Free Unit End Date",
sda.RESULT5_VALUE "Free Unit Priority",
sda.RESULT6_VALUE "Availability",
sda.RESULT7_VALUE "Description",
sda.RESULT8_VALUE "Persona Name",
ph.PRODUCT_NAME "Companion Product Id",
sc.SCHEDULE_NAME "HUK Bill Cycle Schedule"
from service_history sh,
service_da_array sda,
reference_code rc1, -- H3G_FU_CATEGORY
reference_code rc2, -- H3G_FU_TYPE
reference_code rc3, -- H3G_FU_REPEAT
product_history ph, -- Comapanion product list
schedule sc -- Bill cycle list
where sh.SERVICE_NAME = '0831973860'
and sh.SERVICE_STATUS_CODE = 3 -- 3: Active, 9: Cancelled
and sda.SERVICE_ID = sh.SERVICE_ID
and sda.DERIVED_ATTRIBUTE_ID = 3100047
and rc1.REFERENCE_TYPE_ID = 1000023 and rc2.REFERENCE_TYPE_ID = 3100000 and
rc3.REFERENCE_TYPE_ID = 3100085
and (rc1.reference_code*1000000) + (rc2.reference_code*1000) +
(rc3.reference_code) = sda.RESULT1_VALUE
and ph.PRODUCT_ID = sda.RESULT9_VALUE
and sc.SCHEDULE_ID = sda.RESULT10_VALUE
and sysdate between sh.EFFECTIVE_START_DATE and sh.EFFECTIVE_END_DATE
and sysdate between sda.EFFECTIVE_START_DATE and sda.EFFECTIVE_END_DATE
and sysdate between ph.EFFECTIVE_START_DATE and ph.EFFECTIVE_END_DATE
order by sda.INDEX1_VALUE desc

3) Restarting ETL process:

Log on to COLPH001 as Batchman user. Password: volume


Identify failed job:

select * from ctrl_batch_jobs


where status = 'Failed'

Update status of failed job to ‘New’:

update ctrl_batch_jobs
set status = 'New'
where job_process_id = 1503993
and status = 'Failed'

Then

commit

Monitor for status of restarted job:

select * from batch_processes


order by 1 desc

If this continues to fail after restart, use the following query to determine the error, and quote this when
calling out BO on call:

select * from collect_owner.batch_processes t


where step_timestamp> sysdate -7
order by step_timestamp desc

Free Units Query.


select sh.SERVICE_NAME,
srv.KEY_VALUE "Allocation ID",
rc1.abbreviation || ' / ' || rc2.abbreviation || ' / ' || rc3.abbreviation "Category / Type
/ Repeat",
srv.START_DATE,
srv.END_DATE,
srv.EVENT_START_DATE,
srv.EVENT_END_DATE,
sda.RESULT2_VALUE "FU Allocated",
srv.VALUE "FU Consumed",
(sda.RESULT2_VALUE - srv.VALUE) "FU Left"
from service_history sh,
service_da_array sda,
reference_code rc1, -- H3G_FU_CATEGORY
reference_code rc2, -- H3G_FU_TYPE
reference_code rc3, -- H3G_FU_REPEAT
subtotal_rating_value srv
where sh.SERVICE_NAME = '07450539436'
--and srv.KEY_VALUE = ''
--and srv.START_DATE = to_date('06-02-2014 00:00:00','dd-mm-yyyy hh24:mi:ss')
and sh.SERVICE_STATUS_CODE in (3,9)
and sda.SERVICE_ID = sh.SERVICE_ID
and sda.DERIVED_ATTRIBUTE_ID = 3100047
and srv.CUSTOMER_NODE_ID = sh.CUSTOMER_NODE_ID
and srv.KEY_VALUE = sda.INDEX1_VALUE
and rc1.REFERENCE_TYPE_ID = 1000023 and rc2.REFERENCE_TYPE_ID = 3100000 and
rc3.REFERENCE_TYPE_ID = 3100085
and (rc1.reference_code*1000000) + (rc2.reference_code*1000) + (rc3.reference_code) =
sda.RESULT1_VALUE
and sysdate between sh.EFFECTIVE_START_DATE and sh.EFFECTIVE_END_DATE
and sysdate between sda.EFFECTIVE_START_DATE and sda.EFFECTIVE_END_DATE
order by srv.END_DATE desc, srv.KEY_VALUE

Query to find unbilled Amount:

select * from charge


where account_id = '20441935'
and uninvoiced_ind_code is not null
and adjustment_id is null

You might also like