假设我们有200名学生和6名科目。输入列是
Name | Subject1 | Subject2 | ... through Subject 6
输出只有3列:
Name | Subject | Highest Score
我们需要主题最高得分手以及主题名称和得分作为输出。我们将如何在Informatica级别执行此操作?如果不使用union,我们将如何在SQL级别执行此操作?
示例数据:
Name |Sub1 |Sub2 |Sub3 |Sub4 |Sub5 |Sub6
-----+-----+-----+-----+-----+-----+----
A |5 |67 |77 |6 |34 |43
B |54 |54 |32 |3 |23 |21
C |1 |23 |43 |45 |43 |21
答案 0 :(得分:0)
在Informatica中很容易,使用排序方式设置为主题然后得分(升序)。然后聚合器按主题排序输入组。
SQL GROUP BY
会处理它,即
SELECT MAXSCORES.SUBJECT, MAXSCORES.TOPRESULT, RESULTS.STUDENT AS TOPSCORER
FROM (SELECT SUBJECT, MAX(SCORE) AS TOPRESULT FROM RESULTS GROUP BY SUBJECT) AS MAXSCORES
WHERE MAXSCORES.SUBJECT = RESULTS.SUBJECT AND MAXSCORES.TOPRESULT = RESULTS.SCORE