选择后的SQL查询Sum() [英] SQL Query Sum() after selection
本文介绍了选择后的SQL查询Sum()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select case duration when ''Half Day'' then ''.5'' when ''Full Day'' then ''1'' when ''"Hour*"'' then dbo.GetNumbers(duration) else dbo.GetNumbers(duration) end as DURATION from tbl_leave
上面是一个SQL QUERY,结果为
Above is an SQL QUERY,the result is
DURATION
1
115
1
3
.5
我想要持续时间的总和,有人可以帮我吗?/
i want the sum of the DURATION,can anyone help me?/
推荐答案
您尝试过此操作吗?
did you try this
select Sum(case duration when 'Half Day' then '.5' when 'Full Day' then '1' when '"Hour*"' then dbo.GetNumbers(duration) else dbo.GetNumbers(duration) end) as DURATION from tbl_leave
否则,请使用此
other wise use this
select sum(cast(duration as float)) from (
select case duration when 'Half Day' then '.5' when 'Full Day' then '1' when '"Hour*"' then dbo.GetNumbers(duration) else dbo.GetNumbers(duration) end as DURATION from tbl_leave) as LeaveDuration
这两个都应该起作用.
--Pankaj
both of these should work.
--Pankaj
这篇关于选择后的SQL查询Sum()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文