sql查询中的计算问题 [英] calculation problem in sql query
本文介绍了sql查询中的计算问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,我有一个类似的查询: -
sir, i have a query like:-
select (Studentid+semid) as total , 30+((50-30)* (cast(24 as float)/cast(50 as float))) as cal
from student
查询的结果是: -
总计 - cal
6 - 39.6
7 - 39.6
5 - 39.6
8 - 39.6
i需要将我的总列值设置为24。和cal结果基于总列值。我该怎么办。
the result of query is :-
total -- cal
6 -- 39.6
7 -- 39.6
5 -- 39.6
8 -- 39.6
i need that my total column value are set in place of '24'. and cal result is base on total column value. how can i do it.
推荐答案
希望以下代码解决您的问题。
Hi,
Hope the below code solve your problem.
WITH Sample_CTE (total)
AS
(
SELECT (Studentid+semid) as total from student
)
SELECT 30+((50-30)* (cast(total as float)/cast(50 as float))) AS cal
FROM Sample_CTE;
(如果是请标记为已解决)
谢谢
(if yes pls mark as solved)
Thanks
这篇关于sql查询中的计算问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文