由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请问:query about checking consistency
相关主题
今典问题: 这个Self Query咋写?COMBINE RECORDS
问一个关于SQL的问题请教database developer职业发展方向
SP is less performance than Direct SQL Query if using CTE?同事被FIRE掉了
有趣的Join问题,源于SQL和SAS比较。准备考70-433
Interesting Data Manipulation question我经常问的几道SQL SERVER DBA的面试题,图省事不问编程
Late afternoon 腦不好使其实我发现了CODE的写得好不好
[Mysql] how to return NULL count in group by query (转载)到底啥样的人在做contract工作
请问那种很复杂的sql语句,有什么套路吗?15万收入怎么样
相关话题的讨论汇总
话题: cte话题: query话题: attr话题: prev
进入Database版参与讨论
1 (共1页)
z**k
发帖数: 378
1
sorry i cannot type chinese at work.
I have a collection of records, ordered by date, the record has two other
attributes, say attr and prev, here's a simple example:
date, attr, prev
i****a
发帖数: 36252
2
basic idea is to use row_number and self joining tables. if you use CTE,
here is an example
with cte as
(
select ROW_NUMBER() over (order by tb1.colDate) as rn1, *
from tableTest2 tb1
)
select *
from cte
inner join (select ROW_NUMBER() over (order by colDate) as rn2, * from
tableTest2) tb2
on cte.rn1 = tb2.rn2 - 1 and cte.attr <> tb2.prev
if you don't want to use CTE or not on SQL server 2005 or later, then put
result from the 1st query into a temp table
1 (共1页)
进入Database版参与讨论
相关主题
15万收入怎么样Interesting Data Manipulation question
请问如何实现这样一个db2的query, 谢谢Late afternoon 腦不好使
best practices for sql developer[Mysql] how to return NULL count in group by query (转载)
请问这个update query有什么问题?请问那种很复杂的sql语句,有什么套路吗?
今典问题: 这个Self Query咋写?COMBINE RECORDS
问一个关于SQL的问题请教database developer职业发展方向
SP is less performance than Direct SQL Query if using CTE?同事被FIRE掉了
有趣的Join问题,源于SQL和SAS比较。准备考70-433
相关话题的讨论汇总
话题: cte话题: query话题: attr话题: prev