postgre库通过sql语句 六个指标采用熵值法计算得分
时间: 2023-06-30 22:15:40 浏览: 158
在 SQL 语言中,可以通过使用子查询和聚合函数来实现对 postgre 库的六个指标采用熵值法计算得分的功能。下面是一个示例 SQL 语句:
```
SELECT id,
(w1*y1 + w2*y2 + w3*y3 + w4*y4 + w5*y5 + w6*y6) AS score
FROM (
SELECT id,
(x1-x1_min)/(x1_max-x1_min) AS y1,
(x2-x2_min)/(x2_max-x2_min) AS y2,
(x3-x3_min)/(x3_max-x3_min) AS y3,
(x4-x4_min)/(x4_max-x4_min) AS y4,
(x5-x5_min)/(x5_max-x5_min) AS y5,
(x6-x6_min)/(x6_max-x6_min) AS y6,
(1-H1/ln(n))/(wsum-H1/ln(n)) AS w1,
(1-H2/ln(n))/(wsum-H2/ln(n)) AS w2,
(1-H3/ln(n))/(wsum-H3/ln(n)) AS w3,
(1-H4/ln(n))/(wsum-H4/ln(n)) AS w4,
(1-H5/ln(n))/(wsum-H5/ln(n)) AS w5,
(1-H6/ln(n))/(wsum-H6/ln(n)) AS w6
FROM (
SELECT id,
x1, x2, x3, x4, x5, x6,
MAX(x1) OVER () AS x1_max,
MAX(x2) OVER () AS x2_max,
MAX(x3) OVER () AS x3_max,
MAX(x4) OVER () AS x4_max,
MAX(x5) OVER () AS x5_max,
MAX(x6) OVER () AS x6_max,
MIN(x1) OVER () AS x1_min,
MIN(x2) OVER () AS x2_min,
MIN(x3) OVER () AS x3_min,
MIN(x4) OVER () AS x4_min,
MIN(x5) OVER () AS x5_min,
MIN(x6) OVER () AS x6_min,
SUM(ln(n)) OVER () AS ln_n,
SUM((1-x1/sum(x1))^2) OVER () AS H1,
SUM((1-x2/sum(x2))^2) OVER () AS H2,
SUM((1-x3/sum(x3))^2) OVER () AS H3,
SUM((1-x4/sum(x4))^2) OVER () AS H4,
SUM((1-x5/sum(x5))^2) OVER () AS H5,
SUM((1-x6/sum(x6))^2) OVER () AS H6,
SUM((1-x1/sum(x1))^2 + (1-x2/sum(x2))^2 + (1-x3/sum(x3))^2 + (1-x4/sum(x4))^2 + (1-x5/sum(x5))^2 + (1-x6/sum(x6))^2) OVER () AS wsum
FROM my_table
) AS t
) AS t2;
```
其中,`my_table` 是包含六个指标数据的表,`id` 是每个数据的唯一标识符,`x1` 到 `x6` 是六个指标的原始数据。这个 SQL 语句会先对每个指标进行标准化处理,然后计算每个指标的信息熵和权重,最后计算每个数据的得分。得分计算完成后,可以对结果进行排序或者筛选出得分最高的数据。需要注意的是,这个 SQL 语句中的计算公式和参数需要根据具体数据进行调整,以保证计算结果的正确性。
阅读全文