sql - Please this not lining up properly -
please help.. doing wrong here?
select (case when lag(customers.customer_id, 1, null) on (partition customers.customer_id order customers.customer_id) null customers.customer_id else null end) ref, (case when lag(customers.company_name, 1, null) on (partition customers.company_name order customers.company_name) null customers.company_name else null end) company_name, (case when lag(count (calls.call_ref), 1, null) on (partition count (calls.call_ref) order count (calls.call_ref)) null count (calls.call_ref)else null end) total_calls, callers.caller_last_name last_name, count(calls.call_ref)as calls customers inner bring together callers on company_id=customer_id left bring together calls on callers.contact_id=calls.contact_id grouping customers.customer_id , customers.company_name, callers.caller_last_name order customer_id, company_name, calls desc; this result see:
ref company_name total_calls last_name calls ---------- ------------------------------ ----------- -------------------- ---------- haunt services lewis 2 penrice 4 100 4 anderson 4 best 3 williams 2 genus ltd. phillips 4 parker 3 johnson 2 101 davies 2 102 corps ltd. gritten 4 scott 2 103 train services 7 lawson 7 roberts 2 104 logistics baker 2 phillips 4 immemorial shipping powell 3 105 lee 7 williams 4 mock grouping phillips 6 106 harrison 3 juan , co. white 4 turner 3 107 clarke 3 roberts 2 logis shipping thompson 4 108 best 7 1 white 1 packman shipping harris 2 109 brownish 3 jackson 3 here illustration on how should like. total calls added in relation calls made people in specific company. it's not lining me reason. i'm new , still learning may laugh @ it's done wrong!
ref company name total calls lastly name calls no phone call ----- ------------------- ----------- ------------ ---------- ------- 135 dasher services 12 clarke 5 wright 4 turner 3 142 diaphonic shipping 12 hill 5 johnson 5 butler 2 jackson 0 ******* 107 juan , co. 12 white 4 turner 3 clarke 3 roberts 2 sql oracle group-by
No comments:
Post a Comment