2012-09-25 142 views
0

我在格式化查詢的輸出面臨一個問題:格式問題

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; 

其中 RSSEC,總RSeconds(型號)
WCTSEC-總WSeconds(型號)

 
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 

任何人都可以幫助我達到上述格式嗎?

請讓我知道任何替代解決方案獲得以上輸出格式以外的截斷位置。

由於提前,

+0

您使用的是哪種數據庫供應商(Oracle,MS SQL Server,mySQL)?你看過他們的SQL文檔的格式功能嗎? –

回答

0

我不知道哪個RDBMS這個,所以我猜,但這個怎麼樣?

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;