2012-06-25 71 views
0
Select empno,sum(cast(substring(othours,0,3)as float)) as 
Hour,sum(cast(substring(othours,4,5)as float)) as Minutes from tmstrans 
group by empno,othours 

它顯示像以下請糾正我的查詢

  • 1數據,10
  • 1,30
  • 2,10
  • 2,30

我需要以下數據

  • 1,40
  • 2,40

請幫助

+0

刪除'othours'從'BY子句 – spencer7593

回答

3

假設你想SUM兩個小時和分鐘列,你從GROUP BY條款刪除othours列。測試這樣的:

SELECT empno, 
     SUM(CAST(SUBSTRING(othours,0,3) AS float)) AS Hour, 
     SUM(CAST(SUBSTRING(othours,4,5) AS float)) AS Minutes 
FROM tmstrans 
GROUP BY empno 
+0

謝謝group'非常多,問題就解決了 –

+1

@Asifkhan如果這是正確的,你應該接受的答案是:http://meta.stackexchange。 COM /問題/ 5234 /如何-不接受-的回答工作 –