Home » SQL & PL/SQL » SQL & PL/SQL » Nested Select for summary (11g)
Nested Select for summary [message #611155] Fri, 28 March 2014 08:35 Go to next message
andysam23586
Messages: 17
Registered: September 2009
Junior Member
Hi, I have a query which is working fine.
The resulting columns are: Marval Ref, Priority, Description, Breached, Date Occurred, Status, Last Updated, Updated By.

I now need to run a query that gets a summary of information.
The results I need should be
Priority, Total, Breached, %
There are 4 priorities 1, 2, 3 & 4
So the results will be Total number of Priority 1, and out of this total how many breached. Then the same for Priority 2, 3 & 4
The percentage column will be percentage of total breached.

I hope this makes sense.
My code so far is as follows
SELECT
  LCC_TPROBLEM.PNUMBER AS "Marval Ref",
  LCC_TPROBLEM.PPRIORITY AS "Priority",
  LCC_TPROBLEM.PDESCRIPT AS"Description",
  CASE WHEN (LCC_TPROBLEM.PEXFIX = '1')
  THEN 'Yes'
  ELSE 'NO'
  END as Breached,
  
  
 
  To_Date('01/01/1970','DD/MM/YYYY')+(LCC_TPROBLEM.POCCURRED/86400) AS"Date Occurred",
  LCC_TPROBLEM.PSTATUS AS "Status",
  To_Date('01/01/1970','DD/MM/YYYY')+(LCC_TPROBLEM.PMODIFIED/86400) AS "Last Updated",
  LCC_TPROBLEM.PMODIBY AS "Updated By"
  
FROM
  LCC_TPROBLEM,
  LCC_TPROBLEM  MEASURES,
  PURSUIT_TDICT2
WHERE
  ( LCC_TPROBLEM.PNUMBER=MEASURES.PNUMBER  )
  AND  ( PURSUIT_TDICT2.DICTSNO(+)=LCC_TPROBLEM.PDICT2  )
  AND  
  (
   case when LCC_TPROBLEM.PCALLTYPE = 'CHG' Then 'Change'  when LCC_TPROBLEM.PCALLTYPE = 'INC' then 'Incident' when LCC_TPROBLEM.PCALLTYPE = 'PRB' then 'Problem' when LCC_TPROBLEM.PCALLTYPE = 'TSK' then 'Task' else 'Unknown' end  In  ( 'Problem'  )
   AND
   LCC_TPROBLEM.PSTATUS  Not In  ( 'COMPLETE','CLOSED','SOLVED'  )
  )
GROUP BY
  LCC_TPROBLEM.PNUMBER, 
  LCC_TPROBLEM.PPRIORITY, 
  LCC_TPROBLEM.PDESCRIPT, 
  CASE WHEN (LCC_TPROBLEM.PEXFIX = '1')
  THEN 'Yes'
  ELSE 'NO'
  END,
   
  PURSUIT_TDICT2.DICTKEYDES, 
  To_Date('01/01/1970','DD/MM/YYYY')+(LCC_TPROBLEM.POCCURRED/86400), 
  LCC_TPROBLEM.PSTATUS, 
  To_Date('01/01/1970','DD/MM/YYYY')+(LCC_TPROBLEM.PMODIFIED/86400) , 
  LCC_TPROBLEM.PMODIBY, 
  To_Date('01/01/1970','DD/MM/YYYY')+(LCC_TPROBLEM.PNHMOD/86400) 


Many thanks

Andy
Re: Nested Select for summary [message #611156 is a reply to message #611155] Fri, 28 March 2014 08:38 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
since we do not have your tables or data, we can not run, debug or improve posted code.
Re: Nested Select for summary [message #611159 is a reply to message #611156] Fri, 28 March 2014 08:51 Go to previous messageGo to next message
andysam23586
Messages: 17
Registered: September 2009
Junior Member
Do you need just the tables in the query or the whole database as this is a very larg database
Re: Nested Select for summary [message #611161 is a reply to message #611159] Fri, 28 March 2014 08:54 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and please read http://www.orafaq.com/forum/t/174502/102589/
Previous Topic: Sorting Issue
Next Topic: how to use substr if the error ORA-01403: no data found.
Goto Forum:
  


Current Time: Tue Apr 16 18:04:31 CDT 2024