第二条记录与第一条记录之间的差异 [英] Difference between second record and first record

查看:132
本文介绍了第二条记录与第一条记录之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,
正在编写存储过程并遇到一些问题.请帮助我.

我的选择查询是

从TM_Node WHERE Nodedate> = @ PreDate和Nodedate< = @ PostDate和AssociateId = @ AssociateId
中选择LeftCount,RightCount
其中AssociateId是我的PrimaryKey

返回两行.
第二行的记录可能大于第一行或保持不变.

LeftCount RightCount
822 930
822 938

Diffleft = 822-822
区别权= 938-930

我想要一个查询,该查询将使我Diffleft返回0,DiffRight返回8.

Hi Dear,
Am writing a stored procedure and facing some problems.Plz help me out.

My Select Query is

SELECT LeftCount,RightCount FROM TM_Node WHERE Nodedate>=@PreDate and Nodedate<=@PostDate and AssociateId=@AssociateId

Where AssociateId is my PrimaryKey

Returning two rows.
The records of second row may be greater than the first one or remain same.

LeftCount RightCount
822 930
822 938

Diffleft = 822 - 822
DiffRight = 938 - 930

I want a query that will return me Diffleft as 0 and DiffRight as 8.

推荐答案

鉴于您已向试图提供帮助的两个人投了一票您,然后再不客气地再次发布相同的问题,我不确定为什么我仍在尝试帮助您.既然我对问题的理解更好了,那么执行此操作的方法是将值读入您声明的变量中,然后返回它们的差值.像

声明@ left1 int
声明@ left2 int
声明@ right1 int
声明@ right2 int

然后

选择@ left1 = LeftCount,@ right1 = RightCount FROM ...

困难的部分是,您需要弄清楚如何返回left2和right2(top 1将返回第一个值).那你就

选择@ left2-@ left1作为DiffLeft,@ right2-@ right1作为DiffRight
Given that you''ve given one votes to the two people who tried to help you, and then rudely posted the same question again, I''m not sure why I''m still trying to help you. Now that I understand the question a bit better, the way to do this, would be to read the values into variables that you declare, then return their difference. Something like

declare @left1 int
declare @left2 int
declare @right1 int
declare @right2 int

Then

select @left1 = LeftCount, @right1 = RightCount FROM...

The hard part is, you need to figure out how to return left2 and right2 ( top 1 will return the first values ). Then you do

select @left2 - @left1 as DiffLeft, @right2 - @right1 as DiffRight


嗨 您可以使用游标执行此任务.
Hi U can use cursors for to perform this task.


写道:​​

我想要一个查询,该查询将返回我Diffleft为0,DiffRight为8.

I want a query that will return me Diffleft as 0 and DiffRight as 8.



你是什​​么意思?



What do you mean ?


这篇关于第二条记录与第一条记录之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆