我正试图根据某些条件给我的行提供一定数量的点,我不知道该怎么写
对于给定的Id, FormatCode和Price,我想给值1。对于具有相同Id和价格的后续行,如果FormatCode是具有相同Id和价格的前一行的倍数,则我希望给出相同的值。
例如:
00010405, 100, 0.3218 = 1
00010405, 400, 0.3218 = 1
(400% 100 = 0)
00010405, 500, 0.3126 = 2
(500% 100 = 0,但价格不同)
00010405, 1000, 0.3126 = 2
(1000 % 500和1000 % 100 = 0,但格式代码100的价格不同,因此它将取值2,因为它具有相同的价格)
如果我理解正确的话,您希望优先考虑formatCode乘数而不是价格。你应该看看DENSE_RANK
,而不是ROW_NUMBER
。
描述对我来说仍然有点不清楚,但如果我理解正确的话,这里有一个工作示例:
--Setup some sample data
drop table if exists #tmp
select *
into #tmp
from (values
('00010405',100, 0.3218 ),
('00010405',400, 0.3218 ),
('00010405',500, 0.3126 ),
('00010405',1000, 0.3126 ),
('00010405',1333, 0.3126 ),--not a multiple
('00010405',2666, 0.3126 )--multiple of previous row
) as tab(id, formatcode, price)
--Make the calculation
select
t.id,
t.formatcode,
t.price,
DENSE_RANK() over(partition by id order by minMulti.formatCodeMin_multiplier, t.price) as Value
from #tmp t
cross apply(
select min(formatCode) as formatCodeMin_multiplier
from #tmp t2
where t.id = t2.id and t.price = t2.price
and t.formatcode % t2.formatcode = 0
) as minMulti
order by id, formatcode
技巧是找到具有最小值的格式代码,其中当前行的值是。
的乘数。
相关内容
- Power Query中的列表切片代码运行到运行时错误,函数被分配给列表?
- 是否有任何方法可以运行此代码,而不会在切换的第二种情况下使用未分配的局部变量错误?
- 为什么java抛出错误时,试图分配给其他类型的变量在运行时?
- 检查变量如何在堆内存中分配(用于调试运行时错误)
- 只有当两个作业都获得分配的资源时,才运行两个slum作业
- 在Javascript和块范围循环之前分配变量是否运行得更快?
- 在运行时使用ModuleFederationPlugin将publicPath分配给各个远程
- Heap-buffer-overflow返回动态分配块时的运行时错误
- 如何将防火墙标签分配到云运行中的容器?
- 评估和提高将大量CSV数据集加载到R中并将其全部分配给列表对象的运行时效率
- 如何自定义cron在laravel上预先分配的时间运行?
- 有没有办法通过"srun, sbatch, or salloc"增加正在运行的作业的内存分配?
- Angular:验证器是否会移除并重新分配值更改时的错误(当它们运行时)?
- 如何根据某些条件为行分配运行值
- 用户标识角色分配运行良好,但确实显示在门户中
- 如何在熊猫中使用for循环为每列分配运行值?
- 如何修复错误分配C++运行时错误
- 为张量流变量分配运行时值
- C中的内存分配运行时错误
- 创建实例并分配运行时程序集的属性
最新更新
- CSS Sticky属性在本演示中不起作用
- NodeJs与xmlrpc服务器通信,并对node-xmlrpc库进行base64编码,将下载的url图像编码为base
- 在管道中使用powershell如何使用在azure devops中触发的管道运行来获取shelvesset编号.<
- 我希望在表格单元格内的左、右位置的同一行中有不同的文本
- Entity Framework ExecuteDelete没有按预期工作
- 颤振只加载某些riv (.riv)文件
- Python问题我如何循环回我的代码?
- asyncpg.exceptions.InvalidAuthorizationSpecificationError Py
- 为什么我的阅读更多按钮不工作?
- 如何得到拆分字符后的单词
- 在列表框之间移动项
- 设置 SKEmitterNode 的 'targetNode' 会导致奇怪的 'zPosition' 行为
- 我无法在斐波那契数列 python 中加强术语
- 用Jest测试使用jquery获取数据的异步函数
- c#与HTML敏捷包不能得到div类的值
- Python 中的 OOP 层次结构
- 我如何动画下拉菜单的高度使用顺风css
- 无法从字符串比较失败的字符串中删除"—"
- 无法获取熊猫数据帧中的第一列值
- Odoo添加按钮应该重定向到我的模块视图
- r语言 - 我如何得到比例在数据表没有组号重复?
- 无法使用 conda env 导入 OCI 笔记本会话中的模型配置详细信息
- c - while循环中VSC的分段错误
- 无法将url数据获取到模型类中
- 如何将DataGridTextColumn绑定到WinUI3中绑定的对象中的方法?
- 错误在cobol程序上打开VB文件来处理XML文件
- while循环在python中没有爆发
- yii2查询具有多个非和或的数据提供程序
- Libgdx:渲染方法
- Pycharm 错误:预期类型 [类名] 改为"str"
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium