SELECT  
 TO_DAYS(
   CASE A.status 
     WHEN 0 THEN now()
     WHEN 1 THEN now()
     WHEN 2 THEN now()
     WHEN 3 THEN now()
     WHEN 4 THEN now()
     WHEN 5 THEN (IFNULL(A.bugUpdateDate, NOW()))
     WHEN 6 THEN now()
     WHEN 8 THEN (IFNULL(A.comfirmDate, NOW()))
     ELSE NOW()
   END
  )
 - TO_DAYS(A.issuDate) AS TAT,
 A.bno,
 A.status,
 B.nickName AS dispatchName,
 A.title
 FROM Bug AS A
 LEFT JOIN UserInfo AS B ON A.dispatch = B.uno
 HAVING TAT > 6 AND A.status <> 8
 ORDER BY  TAT DESC, A.bno;

/*------------- 統計をとってもあまり意味がない
SELECT  
 A.status,
 TO_DAYS(
   CASE A.status 
     WHEN 0 THEN now()
     WHEN 1 THEN now()
     WHEN 2 THEN now()
     WHEN 3 THEN now()
     WHEN 4 THEN now()
     WHEN 5 THEN (IFNULL(A.bugUpdateDate, NOW()))
     WHEN 6 THEN now()
     WHEN 8 THEN (IFNULL(A.comfirmDate, NOW()))
     ELSE NOW()
   END
  )
 - TO_DAYS(A.issuDate) AS TAT,
 count(*)
 FROM Bug AS A
 GROUP BY A.status, TAT
 ORDER BY A.status, TAT DESC;
-------------*/

/*------------- 統計をとってもあまり意味がない
SELECT  
 A.bno,
 TO_DAYS(A.comfirmDate) - TO_DAYS(A.issuDate) AS tat
 FROM Bug AS A
 WHERE A.comfirmDate IS NOT NULL
 ORDER BY tat DESC, A.bno;
-------------*/

