- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通常我很擅长解决基于集合的 tsql 问题。但这一个打败了我。我花了 3 天的时间将 while 循环过程转换为基于集合的过程。我已经到达下面的点了......但无法进行最后的跳跃。
我有以下几行。 MyOrdinal 将“按顺序”...第二列 (MyMarker) 将在具有值和为空之间交替。每当 MyMarker 上发生这种“翻转”时,我想将“group by”序数计数器增加 1。每当“翻转”值非空或空时,它们就会被分组为一个集合。
我已经尝试了几种方法,但它太难看了,无法发布。自从转向 ORM 以来,我不再在 tsql 上花费太多时间。
declare @Holder table ( MyOrdinal int not null , MyMarker int , MyGroupNumber int )
INSERT INTO @Holder (MyOrdinal, MyMarker)
Select 1 , 1
union all Select 2, 2
union all Select 3, null
union all Select 4, 3
union all Select 5, 4
union all Select 6, 5
union all Select 7, 6
union all Select 8, 7
union all Select 9, 8
union all Select 10, 9
union all Select 11, 10
union all Select 12, 11
union all Select 13, 12
union all Select 14, 13
union all Select 15, 14
union all Select 16, 15
union all Select 17, null
union all Select 18, null
union all Select 19, null
union all Select 20, 16
union all Select 21, 17
union all Select 22, 18
union all Select 23, null
union all Select 24, null
union all Select 25, 19
union all Select 26, 20
union all Select 27, null
union all Select 28, 21
Select * from @Holder
期望的输出
| MyOrdinal | MyMarker | MyGroupNumber |
|-----------|----------|---------------|
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | null | 2 |
| 4 | 3 | 3 |
| 5 | 4 | 3 |
| 6 | 5 | 3 |
| 7 | 6 | 3 |
| 8 | 7 | 3 |
| 9 | 8 | 3 |
| 10 | 9 | 3 |
| 11 | 10 | 3 |
| 12 | 11 | 3 |
| 13 | 12 | 3 |
| 14 | 13 | 3 |
| 15 | 14 | 3 |
| 16 | 15 | 3 |
| 17 | null | 4 |
| 18 | null | 4 |
| 19 | null | 4 |
| 20 | 16 | 5 |
| 21 | 17 | 5 |
| 22 | 18 | 5 |
| 23 | null | 6 |
| 24 | null | 6 |
| 25 | 19 | 7 |
| 26 | 20 | 7 |
| 27 | null | 8 |
| 28 | 21 | 9 |
最佳答案
试试这个:
首先,这会为连续的非NULL
MyMarker
分配相同的ROW_NUMBER
。对于 NULL
MyMarker
来说,ROW_NUMBER
为 NULL
。之后,您需要为 NULL
MyMarker
添加一个 ROW_NUMBER
,使得该值介于之前的 NON-NULL
之间code> 和下一个非 NULL
。然后使用DENSE_RANK
最终分配MyGroupNumber
:
;WITH Cte AS(
SELECT *,
RN = ROW_NUMBER() OVER(ORDER BY MyOrdinal) - MyMarker + 1
FROM @Holder
),
CteApply AS(
SELECT
t.MyOrdinal,
t.MyMarker,
MyGroupNumber =
CASE
WHEN RN IS NULL THEN x.NewRN
ELSE RN
END
FROM Cte t
OUTER APPLY(
SELECT TOP 1 RN * 1.1 AS NewRN
FROM Cte
WHERE
t.MyOrdinal > MyOrdinal
AND MyMarker IS NOT NULL
ORDER BY MyOrdinal DESC
)x
)
SELECT
MyOrdinal,
MyMarker,
MyGroupNumber = DENSE_RANK() OVER(ORDER BY MyGroupNumber)
FROM CteApply
关于sql-server - 基于 "Group By"列运行 "Flip"序数计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29885982/
我正在开发一款小型多人 2d 平台游戏。我已经设法让它在网络上复制动画、移动和翻转 Sprite ,但我有一个我无法理解的错误。翻转 Sprite 的代码非常适合主持人——他可以看到其他玩家在左转或右
好吧,简单的 css 翻转 .container .flipper.A .front .back .flipper.B .front .back 对
我有以下类型定义: newtype Flip f a b = Flip (f b a) deriving (Eq, Show) Flip 数据构造函数是否有一个或三个参数? 考虑以下实现: dat
给定一个用于中缀用法的函数: let f a b = (a+10, b) f 4 5 => (14,5) 4 `f` 5 => (14,5) 可以通过定义辅助函数来翻转参数: let g = flip
我正在以下 URL 中创建一个“艺术家表”:http://beta2.thrivemusic.com/artists/ 如您所见,如果将鼠标悬停在艺术家上方,会出现 3 个社交图标。但是,不同的浏
我想编写一个程序来“反射(reflect)”y 轴上的一串括号。例如,((()( 将变为 )()))。我知道可以这样做: s = '((()(' par = '(', ')' result = ''.
我想让一段文字“翻起来”,就好像它躺在 table 上然后又升起来一样。我的直接问题是 transform-origin - 我无法将文本的轴心点更改为“底部”。 0% {transform:pers
假设我们有一个由 0 和 1 组成的 m x n 网格,我们想要转换网格,使最大行数仅由 1 组成。我们被允许在网格上执行的唯一操作是选择一些列并翻转该列中的所有 0 和 1。我们还得到一些整数 k
我正在使用相当简单的 CSS 过渡来创建一个框,该框通过同时将两个 div 过渡 180 度来“翻转”。当您在盒子的“背面”时,它应该是稍微透明的,以便您可以看到底部。 除了最新的 Safari 7
numpy.flip(m, axis=None) Reverse the order of elements in an array along the given axis. The
我是编程初学者,我正在尝试使用 React 中的 FLIP 技术构建页面布局,但我卡住了,所以我想寻求您的帮助。有关 FLIP 技术的更多信息,请参阅引用 URL。 很快,我想构建一个页面布局,它由一
我最近看到一个面试问题,问以下问题: Given a 32 bit number, write pseudo code to flip the second last bit 最好/最简单的方法是什么
Prelude 的类型功能 flip是: flip :: (a -> b -> c) -> b -> a -> c 即,它需要一个二进制函数和两个参数。 Prelude 的类型功能 id是: id :
在 Haskell 中,我们有一个 flip功能:flip f x y = f y x ,它本质上接受一个函数并返回相同的函数,只是交换了两个参数。我想知道 OCaml 中是否有对应的,因为我找不到并
我有一个 UIView 用于绘制一组项目中的任何一个。也就是说,我的一个 UIView 子类可以被告知绘制一个正方形、圆形或三角形。 我想要一个过渡来翻转该 View ,以便 UIView 在中间点绘
我正在使用jquery插件jquery Flip https://nnattawat.github.io/flip/在我的网页中创建一个卡片翻转系统。该文档指定了一种从元素取消注册翻转事件的方法,我已
在 System.Console.GetOpt 文档中给出的第二个示例(在此处复制)中,我无法理解或解压此行: (o,n,[] ) -> return (foldl (flip id) defaul
这个问题在这里已经有了答案: Why does Haskell's "flip id" has this type? (1 个回答) 6年前关闭。 为什么是 flip id接受为有效表达?它不应该在
查看 ($) 和 flip 的类型: ghci> :t ($) ($) :: (a -> b) -> a -> b ghci> :t flip flip :: (a -> b -> c) -> b -
我非常清楚什么时候 ByteBuffer 需要翻转。我的问题是在 put-er 和 get-er 之间建立隐式契约以减少错误。 在将缓冲区提供给 setter/getter 之前,推杆是否会翻转?或者
我是一名优秀的程序员,十分优秀!