SQL Select 数据 JOIN 过滤重复
SQL Select Data JOIN Filtering Duplicate
我在数据库中有记录:
Table Table 评估的替代 JOIN
SELECT a.id_alternative,a.value,a.id_criteria,b.name FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative ORDER BY a.id_criteria ASC
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
2|14|1|Restiyanti
2|3|2|Restiyanti
3|3|2|Mutiya
2|2|3|Restiyanti
3|3|3|Mutiya
尝试像这样使用 GROUP :
SELECT a.id_alternative, a.value, a.id_criteria, b.name FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative GROUP BY a.id_criteria ORDER BY a.id_criteria ASC
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
3|3|2|Mutiya
3|3|3|Mutiya
问题,我要结果数据记录:
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
3|3|2|Mutiya
3|3|3|Mutiya
2|14|1|Restiyanti
2|3|2|Restiyanti
2|2|3|Restiyanti
请帮忙sql查询上面数据的结果?
你不需要 group by
,只需要 order by col1, col2
SELECT a.id_alternative, a.value, a.id_criteria, b.name
FROM saw_evaluations AS a
JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative
ORDER BY b.id_alternative desc, a.id_criteria asc
尝试不使用 Group By
和 Order
SELECT a.id_alternative, a.value, a.id_criteria, b.name
FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative
ORDER BY a.id_criteria DESC, value DESC
我在数据库中有记录:
Table Table 评估的替代 JOIN
SELECT a.id_alternative,a.value,a.id_criteria,b.name FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative ORDER BY a.id_criteria ASC
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
2|14|1|Restiyanti
2|3|2|Restiyanti
3|3|2|Mutiya
2|2|3|Restiyanti
3|3|3|Mutiya
尝试像这样使用 GROUP :
SELECT a.id_alternative, a.value, a.id_criteria, b.name FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative GROUP BY a.id_criteria ORDER BY a.id_criteria ASC
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
3|3|2|Mutiya
3|3|3|Mutiya
问题,我要结果数据记录:
id_alternative|value|id_criterias|name
-----------------------------------------
3|16|1|Mutiya
3|3|2|Mutiya
3|3|3|Mutiya
2|14|1|Restiyanti
2|3|2|Restiyanti
2|2|3|Restiyanti
请帮忙sql查询上面数据的结果?
你不需要 group by
,只需要 order by col1, col2
SELECT a.id_alternative, a.value, a.id_criteria, b.name
FROM saw_evaluations AS a
JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative
ORDER BY b.id_alternative desc, a.id_criteria asc
尝试不使用 Group By
和 Order
SELECT a.id_alternative, a.value, a.id_criteria, b.name
FROM saw_evaluations AS a JOIN saw_alternatives AS b ON a.id_alternative = b.id_alternative
ORDER BY a.id_criteria DESC, value DESC