-1

我有一个看起来像这样的表:

编号 | 姓名 | 金额 1 jesse 192$ 2 sam 123$ 3 steve 345$ 4 josh 234$ 5 hamish 452$ 6 john 211$ 7 watson 111$ 8 amir 143$ 9 riaz 311$ 10 panag 139$ 现在,我想要顶部的 id金额最高的3人。我搜索了一些像窗口函数,聚合组件但我真的找不到我需要的东西。谁能帮我这个?

我希望结果看起来像

ID 金额 5 452$ 3 345$ 9 311$

4

2 回答 2

1

您需要使用排名组件,按金额排序,窗口函数=行号。然后将其输入过滤器组件,并选择行号 <=3

于 2021-01-10T05:58:43.150 回答
0

您是否可以使用 Matillion 数据库查询组件简单地运行 SQL 命令 - 类似于以下示例中的 SELECT ?

CREATE OR REPLACE TEMPORARY TABLE stacko_q 
AS
    SELECT 1 as id, 'jesse' as nm, 192 as amount UNION ALL
    SELECT 2 as id, 'sam' as nm, 123 as amount UNION ALL
    SELECT 3 as id, 'steve' as nm, 345 as amount UNION ALL
    SELECT 4 as id, 'josh' as nm, 234 as amount UNION ALL
    SELECT 5 as id, 'hamish' as nm, 452 as amount UNION ALL
    SELECT 6 as id, 'john' as nm, 211 as amount UNION ALL
    SELECT 7 as id, 'watson' as nm, 111 as amount UNION ALL
    SELECT 8 as id, 'amir' as nm, 143 as amount UNION ALL
    SELECT 9 as id, 'riaz' as nm, 311 as amount UNION ALL
    SELECT 10 as id, 'panag' as nm, 139 as amount;

SELECT id, amount
FROM (
  SELECT  id, 
          amount, 
          rank() OVER (order by amount desc) my_rank
  FROM stacko_q)
WHERE my_rank <= 3;

--  results - 3 rows
--  ID  AMOUNT
--  5   452
--  3   345
--  9   311

我希望这会有所帮助...丰富

ps 如果这个(或另一个)答案对您有帮助,请花点时间“接受”有帮助的答案,方法是单击答案旁边的复选标记,将其从“灰色”切换为“已填写”。

于 2021-01-06T14:33:41.580 回答