提问人:TadeG 提问时间:11/15/2023 最后编辑:TadeG 更新时间:11/15/2023 访问量:32
SQL 按行减去成本
SQL Subtracting Cost by Rows
问:
我有一个数据集
--City Brand Cost Date
--Nashville A $100 11/14/2023
--Nashville A $125 11/15/2023
我想看看
--City Brand Difference Latest Date
--Nashville A $25 11/15/2023
提前致谢!!
跟RankedCombination
分手结束 行号 <= 1
等
答:
0赞
Khalil
11/15/2023
#1
以下 sql 在 Oracle 中给出了所需的结果:
select city,brand,difference,datecol
from (select rownum as r,city,brand,
cost - lead(cost) over (order by datecol desc) as difference,
datecol
from t1 order by datecol desc)
where r=1;
评论
0赞
TadeG
11/15/2023
我收到错误“ORDER BY 子句在视图、内联函数、派生表、子查询和公共表表达式中无效 select city, brand, difference, newdate from (select row_num as r, city, brand, cost 0 lead(cost) over (order by newdate desc) as difference, newdate where #T_temp order by newdate) where are=1
下一个:如何选择关系只有一个条件的客户
评论