0

I am facing a problem in formatting the output of a query:

  SELECT i.product AS "Product Line",
  COUNT(i.incident_id) "Count Of Tickets",
  TRUNC((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 86400)
  || ':'
  || TRUNC(MOD(((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 3600),24))
  || ':'
  || TRUNC(MOD(((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 60),60))
  || ':'
  || TRUNC(MOD((SUM( NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)),60)) AS "MTTR"
FROM info i; 

where RSSEC-Total RSeconds(type number)
WCTSEC- Total WSeconds(type number)

Current Output:
TTPLL       8   2:4:0:18
ASDASDADD   1   0:0:9:0
UASDF       2   0:0:0:8
ERTEU       4   0:3:0:46
Expected Output:
TTPLL       8   02:04:00:18
ASDASDADD   1   00:00:09:00
UASDF       2   00:00:00:08
ERTEU       4   00:03:00:46

Can anyone help me out to achieve the above format?

Please let me know for any alternative solution to get above output format other than truncate position.

Thanks in advance,

1
  • What database vendor (Oracle, MS SQL Server, mySQL) are you using? Have you looked at their SQL documentation for format functions? Sep 25, 2012 at 11:32

1 Answer 1

0

I don't know which RDBMS this is, so I'm guessing, but how about this one?

  SELECT i.product AS "Product Line",
  COUNT(i.incident_id) "Count Of Tickets",
  RIGHT('0' || TRUNC((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 86400), 2)
  || ':'
  || RIGHT('0' || TRUNC(MOD(((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 3600),24)), 2)
  || ':'
  || RIGHT('0' || TRUNC(MOD(((SUM(NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)) / 60),60)), 2)
  || ':'
  || RIGHT('0' || TRUNC(MOD((SUM( NVL(RSSEC,0) - NVL(WCTSEC,0))/COUNT(i.incident_id)),60)), 2) AS "MTTR"
FROM info i; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.