【问题标题】:I need to find in which subject the student has scored the highest marks in matillion我需要找出学生在哪个科目中获得了最高分
【发布时间】:2020-12-13 13:50:46
【问题描述】:

我需要使用 matillion 找出学生在哪个科目中得分最高(只有科目名称就足够了) 我的数据是这样的

studentid   maths   science art computer sports
1             55     68      59   75     62
2             75     68      79   56     89
3             89     85      74   32     56
4             89     92      86   75     12
5             99     100     45  68      45

我希望我的结果看起来像这样

studentid     highestmark
1              computer
2              sports
3              maths
4              science                     
5              science 

  

【问题讨论】:

    标签: sql snowflake-cloud-data-platform matillion


    【解决方案1】:

    我也加入了 Gordon 的答案以获得最高分。

    选择 t.*, (案例最大(数学、科学、艺术、计算机、运动) 当数学然后'数学' 当科学然后是“科学” 当艺术然后“艺术” 当计算机然后“计算机” 当运动然后是“运动” 结束)作为最高分,

    greatest(数学、科学、艺术、计算机、运动)最高标记 从 t;

    【讨论】:

    【解决方案2】:

    在 Snowflake 或大多数 SQL 方言中,您可以使用greatest()

    select t.*,
           (case greatest(maths, science, art, computer, sports)
               when maths then 'maths'
               when science then 'science'
               when art then 'art'
               when computer then 'computer'
               when sports then 'sports'
            end) as highestmark
    from t;
    

    【讨论】:

    • 对不起@gordonlinoff 我还需要在该主题中显示标记,它应该看起来像 1 个数学 99
    • @Gowtham_7 。 . .这不是你在这里问的问题,但你可以使用greatest() 函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 2023-02-06
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多