我想获得不同的"SkillCategory"
并按id
这是以下脚本:
SELECT distinct EC.SKILL_CATEGORY from ETOPS_CHECK_FORM E
INNER JOIN EC_FORM_SKILL EC
ON EC.EC_FORM_ID=E.ID group by EC.SKILL_CATEGORY ORDER BY EC.ID
我做错了什么?
答案 0 :(得分:3)
问题是您需要决定要排序的 ID。删除distinct
,然后在order by
:
SELECT EC.SKILL_CATEGORY
FROM ETOPS_CHECK_FORM E INNER JOIN
EC_FORM_SKILL EC
ON EC.EC_FORM_ID = E.ID
GROUP BY EC.SKILL_CATEGORY
ORDER BY MIN(EC.ID);
答案 1 :(得分:0)
如果您只想要不使用聚合函数的不同记录,请使用 DISTINCT 关键字而不是 GROUP BY
试试这个:
SELECT DISTINCT EC.SKILL_CATEGORY
FROM ETOPS_CHECK_FORM E
INNER JOIN EC_FORM_SKILL EC ON EC.EC_FORM_ID = E.ID
ORDER BY EC.ID;
答案 2 :(得分:0)
SELECT distinct EC.SKILL_CATEGORY
FROM ETOPS_CHECK_FORM E
INNER JOIN EC_FORM_SKILL EC
ON EC.EC_FORM_ID=E.ID
GROUP BY EC.SKILL_CATEGORY ASC
ORDER BY MAX(EC.ID)
答案 3 :(得分:0)
我想知道你真正想做什么...... ^^ 但是,如果您运行下面的脚本,您能否告诉我们结果是否符合您的期望:
Select ec.skill_category as sc
from EC_FORM_SKILL ec
group by sc;
稍后见。