如何在 Table 视图中查找每个条件的最大值
How to Find Max Value for each criteria in a Table View
我的数据库名为“spkfu”,我的最终项目有四个 table。
第一个 table 是“另类”
id_alternative
name
1
Alex
2
Felix
第二 table 是“条件”
table 包含专家
确定的标准的权重
id_criteria
name_criteria
weight_value1
weight_value2
weight_value3
1
Job
0.40
0.60
0.80
2
School
0.75
0.85
0.95
3
Income
0.50
0.75
1.00
第三个 table 是“间隔”
这 table 具有每个标准的值
id_interval
id_criteria
value_criteria
value_interval
fuzzy_number1
fuzzy_number2
fuzzy_number3
1
1
1
low
0.00
0.25
0.50
2
1
2
med
0.25
0.50
0.75
3
1
3
high
0.50
0.75
1.00
4
2
1
low
0.00
0.25
0.50
5
2
2
med
0.25
0.50
0.75
6
2
3
high
0.50
0.75
1.00
7
3
1
low
0.00
0.25
0.50
8
3
2
med
0.25
0.50
0.75
9
3
3
high
0.50
0.75
1.00
第四个table是“技术方面”
这个table有每个选项的值和已经填写的条件
id_tehnical_aspect
id_alternative
id_criteria
value_criteria
1
1
1
1
2
1
2
1
3
1
3
3
4
2
1
3
5
2
2
2
6
2
3
1
我的Table查看“v_datanilaikriteria”这个table是完整版的测评方面table
id_alternative
id_criteria
value_criteria
fuzzy_number1
fuzzy_number2
fuzzy_number3
1
1
1
0.00
0.25
0.50
1
2
1
0.00
0.25
0.50
1
3
3
0.50
0.75
1.00
2
1
3
0.50
0.75
1.00
2
2
2
0.25
0.50
0.75
2
3
1
0.00
0.25
0.50
查看此代码 table
select `spkfu`.`alternative`.`id_alternative` AS `id_alternative`,`spkfu`.`criteria`.`id_criteria`
AS `id_criteria`,`spkfu`.`technical_aspect`.`value_criteria`
AS `value_criteria`,`spkfu`.`intervals`.`fuzzy_number1`
AS `fuzzy_number1`,`spkfu`.`intervals`.`fuzzy_number2`
AS `fuzzy_number2`,`spkfu`.`intervals`.`fuzzy_number3`
AS `fuzzy_number3` from (((`spkfu`.`technical_aspect` join `spkfu`.`alternative` on(`spkfu`.`alternative`.`id_alternative` = `spkfu`.`tehcnical_aspect`.`id_alternative`))
join `spkfu`.`criteria` on(`spkfu`.`criteria`.`id_criteria` = `spkfu`.`tehcnical_aspect`.`id_criteria`))
join `spkfu`.`intervals` on(`spkfu`.`intervals`.`id_criteria` = `spkfu`.`technical_aspect`.`id_criteria` and `spkfu`.`intervals`.`value_criteria` = `spkfu`.`technical_aspect`.`value_criteria`))
如何从众多备选方案中为每个标准找到最大值 (fuzzy_number3),我需要这样的结果:
id_kriteria
max_number
1
1.00
2
0.75
3
1.00
我试图找到最大值,但每个 table 只能找到 1 个标准
使用此代码
select max(`spkfu`.`intervals`.`fuzzy_number3`) AS `max_k1`,`spkfu`.`criteria`.`id_criteria` AS
`id_criteria` from (((`spkfu`.`technical_aspect` join `spkfu`.`alternative`
on(`spkfu`.`alternative`.`id_alternative` = `spkfu`.`technical_aspect`.`id_alternative`)) join
`spkfu`.`criteria` on(`spkfu`.`criteria`.`id_criteria` = `spkfu`.`technical_aspect`.`id_criteria`))
join `spkfu`.`intervals` on(`spkfu`.`intervals`.`id_criteria` =
`spkfu`.`technical_aspect`.`id_criteria` and `spkfu`.`intervals`.`value_criteria` =
`spkfu`.`technical_aspect`.`value_criteria`)) where `spkfu`.`criteria`.`id_criteria` = '1'
结果
max_k1
id_criteria
1.00
1
去掉where条件和group by
id.criteria
select max(`intervals`.`fuzzy_number3`) AS `max_k1`,
`criteria`.`id_criteria` AS `id_criteria`
from (((`technical_aspect`
join `alternative` on(`alternative`.`id_alternative` = `technical_aspect`.`id_alternative`))
join `criteria` on (`criteria`.`id_criteria` = `technical_aspect`.`id_criteria`))
join `intervals` on (`intervals`.`id_criteria` =
`technical_aspect`.`id_criteria` and `intervals`.`value_criteria` =
`technical_aspect`.`value_criteria`))
group by id_criteria;
演示:https://www.db-fiddle.com/f/7yUJcuMJPncBBnrExKbzYz/36
我的数据库名为“spkfu”,我的最终项目有四个 table。
第一个 table 是“另类”
id_alternative | name |
---|---|
1 | Alex |
2 | Felix |
第二 table 是“条件” table 包含专家
确定的标准的权重id_criteria | name_criteria | weight_value1 | weight_value2 | weight_value3 |
---|---|---|---|---|
1 | Job | 0.40 | 0.60 | 0.80 |
2 | School | 0.75 | 0.85 | 0.95 |
3 | Income | 0.50 | 0.75 | 1.00 |
第三个 table 是“间隔” 这 table 具有每个标准的值
id_interval | id_criteria | value_criteria | value_interval | fuzzy_number1 | fuzzy_number2 | fuzzy_number3 |
---|---|---|---|---|---|---|
1 | 1 | 1 | low | 0.00 | 0.25 | 0.50 |
2 | 1 | 2 | med | 0.25 | 0.50 | 0.75 |
3 | 1 | 3 | high | 0.50 | 0.75 | 1.00 |
4 | 2 | 1 | low | 0.00 | 0.25 | 0.50 |
5 | 2 | 2 | med | 0.25 | 0.50 | 0.75 |
6 | 2 | 3 | high | 0.50 | 0.75 | 1.00 |
7 | 3 | 1 | low | 0.00 | 0.25 | 0.50 |
8 | 3 | 2 | med | 0.25 | 0.50 | 0.75 |
9 | 3 | 3 | high | 0.50 | 0.75 | 1.00 |
第四个table是“技术方面” 这个table有每个选项的值和已经填写的条件
id_tehnical_aspect | id_alternative | id_criteria | value_criteria |
---|---|---|---|
1 | 1 | 1 | 1 |
2 | 1 | 2 | 1 |
3 | 1 | 3 | 3 |
4 | 2 | 1 | 3 |
5 | 2 | 2 | 2 |
6 | 2 | 3 | 1 |
我的Table查看“v_datanilaikriteria”这个table是完整版的测评方面table
id_alternative | id_criteria | value_criteria | fuzzy_number1 | fuzzy_number2 | fuzzy_number3 |
---|---|---|---|---|---|
1 | 1 | 1 | 0.00 | 0.25 | 0.50 |
1 | 2 | 1 | 0.00 | 0.25 | 0.50 |
1 | 3 | 3 | 0.50 | 0.75 | 1.00 |
2 | 1 | 3 | 0.50 | 0.75 | 1.00 |
2 | 2 | 2 | 0.25 | 0.50 | 0.75 |
2 | 3 | 1 | 0.00 | 0.25 | 0.50 |
查看此代码 table
select `spkfu`.`alternative`.`id_alternative` AS `id_alternative`,`spkfu`.`criteria`.`id_criteria`
AS `id_criteria`,`spkfu`.`technical_aspect`.`value_criteria`
AS `value_criteria`,`spkfu`.`intervals`.`fuzzy_number1`
AS `fuzzy_number1`,`spkfu`.`intervals`.`fuzzy_number2`
AS `fuzzy_number2`,`spkfu`.`intervals`.`fuzzy_number3`
AS `fuzzy_number3` from (((`spkfu`.`technical_aspect` join `spkfu`.`alternative` on(`spkfu`.`alternative`.`id_alternative` = `spkfu`.`tehcnical_aspect`.`id_alternative`))
join `spkfu`.`criteria` on(`spkfu`.`criteria`.`id_criteria` = `spkfu`.`tehcnical_aspect`.`id_criteria`))
join `spkfu`.`intervals` on(`spkfu`.`intervals`.`id_criteria` = `spkfu`.`technical_aspect`.`id_criteria` and `spkfu`.`intervals`.`value_criteria` = `spkfu`.`technical_aspect`.`value_criteria`))
如何从众多备选方案中为每个标准找到最大值 (fuzzy_number3),我需要这样的结果:
id_kriteria | max_number |
---|---|
1 | 1.00 |
2 | 0.75 |
3 | 1.00 |
我试图找到最大值,但每个 table 只能找到 1 个标准 使用此代码
select max(`spkfu`.`intervals`.`fuzzy_number3`) AS `max_k1`,`spkfu`.`criteria`.`id_criteria` AS
`id_criteria` from (((`spkfu`.`technical_aspect` join `spkfu`.`alternative`
on(`spkfu`.`alternative`.`id_alternative` = `spkfu`.`technical_aspect`.`id_alternative`)) join
`spkfu`.`criteria` on(`spkfu`.`criteria`.`id_criteria` = `spkfu`.`technical_aspect`.`id_criteria`))
join `spkfu`.`intervals` on(`spkfu`.`intervals`.`id_criteria` =
`spkfu`.`technical_aspect`.`id_criteria` and `spkfu`.`intervals`.`value_criteria` =
`spkfu`.`technical_aspect`.`value_criteria`)) where `spkfu`.`criteria`.`id_criteria` = '1'
结果
max_k1 | id_criteria |
---|---|
1.00 | 1 |
去掉where条件和group by
id.criteria
select max(`intervals`.`fuzzy_number3`) AS `max_k1`,
`criteria`.`id_criteria` AS `id_criteria`
from (((`technical_aspect`
join `alternative` on(`alternative`.`id_alternative` = `technical_aspect`.`id_alternative`))
join `criteria` on (`criteria`.`id_criteria` = `technical_aspect`.`id_criteria`))
join `intervals` on (`intervals`.`id_criteria` =
`technical_aspect`.`id_criteria` and `intervals`.`value_criteria` =
`technical_aspect`.`value_criteria`))
group by id_criteria;
演示:https://www.db-fiddle.com/f/7yUJcuMJPncBBnrExKbzYz/36