Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQL Server中计算行之间的分布计数_Sql_Sql Server_Sql Server 2016 - Fatal编程技术网

如何在SQL Server中计算行之间的分布计数

如何在SQL Server中计算行之间的分布计数,sql,sql-server,sql-server-2016,Sql,Sql Server,Sql Server 2016,如何使用示例检索输出: CREATE TABLE yourTable ( id varchar(55), code int, count1 int, count2 int ); INSERT INTO yourTable (id, code,count1,count2) VALUES ('no-29', 12345, 4, 1), ('no-29', 32346, 4, 1) 始终count1-count2和结果分布在具有相同id的

如何使用示例检索输出:

CREATE TABLE yourTable 
(
     id varchar(55), 
     code int,
     count1 int,
     count2 int
);

INSERT INTO yourTable (id, code,count1,count2)
VALUES
    ('no-29', 12345, 4, 1),
    ('no-29', 32346, 4, 1)
始终count1-count2和结果分布在具有相同id的其他行之间: 示例:4-1=3和3在12345和32346之间的分布

我也希望按id和代码的顺序分布1,1和1,0(因为3是奇数,如果偶数=>1,1和1,1=>countdistribute for codes是2,2)

输出:

id         code    countdistribute
----------------------------------
'no-29'    12345        2
'no-29'    32346        1

我真的不明白你想在这里描述什么。对于
id
具有相同值的两行,对于
count1
count2
具有不同的值。如果
count2
的值大于
count1
?如果count2大于count1意味着第一行的值为2-3=-1,第二行的值为0,那么
count1
count2
与此问题有什么关系?count1和count2是stockno解决方案的输入和存在计数?。。。