首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何选择每个分店总共3枚?

如何选择每个分店总共3枚?
EN

Stack Overflow用户
提问于 2020-11-22 11:22:24
回答 2查看 32关注 0票数 1

我希望每个分行只选择3个OBS,在这里我需要回答以下规则:

如果分支机构只有2个账户--如果分支机构中只有2个最高收入,则为第一个分支机构的2个最高收入帐户,如果该分支机构中有3个帐户,则为第二个帐户twice

  1. ;如果每个分支账户有4个或更多帐户,则为
  2. ,则每个分支账户中有4个或4个以上帐户--每个帐户的观察值为1,这是最高的帐户--,但不重复相同的帐户

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-22 12:39:25

嗯嗯。。。row_id列似乎是在命令帐户内的收入。因此,您应该能够使用proc sql,尽管它有点混乱:

代码语言:javascript
复制
select t.*
from t join
     (select crm_branch_id, count(distinct account_id) as cnt
      from t
      group by crm_branch_id
     ) b
     on b.crm_branch_id = t.crm_branch_id
where (cnt = 1 and t.row_id <= 3) or
      (cnt = 2 and t.row_id = 1 or
       cnt = 2 and t.row_id = 2 and
       t.income = (select max(t2.income)
                 from t t2
                 where t2.crm_branch_id = t.crm_branch_id and
                       t2.row_id = 2
                )
      ) or
      (cnt = 3 and row_id = 1) or
      (cnt > 3 and row_id = 1 and
       (select count(*)
        from t t2
        where t2.crm_branch_id = t.crm_branch_id and
              t2.row_id = 1 and
              t2.income >= t.income
       ) <= 3
      );

where子句中的神秘逻辑是处理不同数量的帐户:

如果有一个帐户,则取前三行。如果有两个帐户,则使用row_id = 2.

  • If有三个帐户的两行,然后是row_id = 2.

  • If有三个帐户的最上面一行,使用row_id = 1.

  • If的行有四个或更多帐户,只考虑有row_id = 1的行。然后以收入为基础,选出前三名。--
票数 0
EN

Stack Overflow用户

发布于 2020-11-22 16:44:18

陶氏处理可以执行肤色选择。

branch

  • Second循环中的
  • 第一个循环,account的计数数,根据规则输出的顶级income
    • 要求数据按以下方式预先排序:
      • branch
      • 中连续

示例:

代码语言:javascript
复制
data have;
input income account_id branch_id seq_act;
datalines;
 1224932 123 358 1
  700400 123 358 2
  646730 123 358 3
  644677 123 358 4
    2017 123 358 5
11338320 567 358 1
 3806060 567 358 2
 3642089 567 358 3
 1403174 567 358 4
  400530 567 358 5
;

/* presume data is
 * - contiguous by branch and account
 * - descending income
 * - ascending seq_act
 */

data want(drop=i n);
  * count number of accounts in branch;
  do until (last.branch_id);
    set have;
    by branch_id account_id notsorted descending income /*ascending*/ seq_act;

    n + first.account_id;
  end;

  do until (last.branch_id);

    set have;
    by branch_id account_id notsorted;

    i + first.account_id;

    select (n);
      when (1) if seq_act <= 3 then output;   /* first 3 when 1 account */
      when (2) if seq_act <= 3-i then output; /* first 2 then first 1 when 2 accounts */
      otherwise if seq_act = 1 then output;   /* first 1 from each account */
    end;
  end;

  i = 0;
  n = 0;
run;

输出

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64953564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档