Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 翻译SQL';s第一个_值并按分区到SAS中_Oracle_Sas_Partitioning_Proc Sql - Fatal编程技术网

Oracle 翻译SQL';s第一个_值并按分区到SAS中

Oracle 翻译SQL';s第一个_值并按分区到SAS中,oracle,sas,partitioning,proc-sql,Oracle,Sas,Partitioning,Proc Sql,我有这个SQL代码 SELECT acc_id, time, approved_amount, balance, coalesce(approved_amount, first_value(balance) OVER (PARTITION BY acc_id ORDER BY time)) orig_amount FROM table; 是否有可能以某种方式将其转

我有这个SQL代码

SELECT acc_id,
   time,
   approved_amount,
   balance,
   coalesce(approved_amount,
            first_value(balance) OVER (PARTITION BY acc_id
                                       ORDER BY time)) orig_amount
   FROM table;

是否有可能以某种方式将其转换为SAS?它在
proc-sql
步骤中不起作用。

我不使用也不知道SAS,但是如果它不支持窗口函数,可以用连接来替换它。我假设您希望coalesce的第二个参数作为acc_id组中最早记录的余额,因此:

select acc_id,
  time,
  approved_amount,
  balance,
  coalesce(approved_amount, acc_id_to_balance.balance_fallback)
from table t
join (
  select t.acc_id, t.balance as balance_fallback
  from (
    select acc_id, min(time) as min_time
    from table
    group by acc_id
  ) acc_id_to_min_time
  join table t on acc_id_to_min_time.acc_id = t.acc_id and acc_id_to_min_time.min_time = t.time
) acc_id_to_balance on t.acc_id = acc_id_to_balance.acc_id

只是在头脑中锻炼,没有尝试。在重复最短时间的情况下可能会出现问题,这需要另一个级别的分组。

这是在SAS中执行此操作的方式,因为与使用数据步骤时的SQL不同,它将按照数据在源数据集中的显示顺序处理数据

data want;
  set table ;
  by acc_id time;
  if first.id then first_balance=balance;
  retain first_balance;
  orig_amount = coalesce(approved_amount,first_balance);
run;

谢谢,在我将
t.
下标添加到列名之前后,似乎正在工作!