[英]How to set ranges on data from SQL Server in ASP.NET with c#
I am creating a page on which there is a map of India. 我正在创建一个页面,上面有印度地图。 I have inserted data into the SQL Server database about economic indicators.
我已经将有关经济指标的数据插入到SQL Server数据库中。 I have also placed a map of India on the webpage.
我还在网页上放置了印度地图。
I want to be able to retrieve the data from the database and then get the greatest value from the data and set it as 100%. 我希望能够从数据库中检索数据,然后从数据中获取最大价值并将其设置为100%。 Then based on that if a value falls between 0 to 20% a that part of the map should be a certain color.
然后根据该值,如果值介于0到20%之间,则地图的该部分应为特定颜色。 If it falls between 20 to 40% it will be a different color and so on.
如果介于20%到40%之间,它将是不同的颜色,依此类推。
I am new to ASP.NET and SQL Server and not sure how to do this. 我是ASP.NET和SQL Server的新手,不确定如何执行此操作。 I really need help.
我真的需要帮助 Thank you in advance
先感谢您
Try something like this. 尝试这样的事情。
WITH cte
AS (SELECT states,
value,
( value / NULLIF(Max(value)
OVER(), 0) ) * 100 AS [Percent]
FROM yourtable)
SELECT states,
value,
color = CASE
WHEN [percent] BETWEEN 0 AND 20 THEN 'X color'
WHEN [percent] BETWEEN 21 AND 40 THEN 'Y color'
WHEN [percent] BETWEEN 41 AND 60 THEN 'X color'
.....
END
FROM cte
Notes : 注意事项:
(Value/max_value) * 100
. (Value/max_value) * 100
公式。 Please correct if it is wrong. value
as the column for which you need to find percentage value
视为需要查找百分比的列 NULLIF
is used to avoid divide by zero error NULLIF
用于避免除以零错误 Max() Over()
is to find the largest value in your table Max() Over()
用于查找表中的最大值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.