Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.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联接查询检索计数_Sql_Sql Server - Fatal编程技术网

从SQL联接查询检索计数

从SQL联接查询检索计数,sql,sql-server,Sql,Sql Server,基本上,它是一个内部连接,它查看一个框中的产品列表,然后查看这些产品的重量 所以我的结果中有两列,乘积,然后是每个乘积的权重 有没有一种简单的方法可以获取此查询中列出的权重之和 谢谢这将为您提供每个不同的productid的总重量 SELECT table.productid, product.weight FROM table1 INNER JOIN product ON table1.productid=product.productid where table1.box = '55555'

基本上,它是一个内部连接,它查看一个框中的产品列表,然后查看这些产品的重量

所以我的结果中有两列,乘积,然后是每个乘积的权重

有没有一种简单的方法可以获取此查询中列出的权重之和


谢谢

这将为您提供每个不同的
productid
的总重量

SELECT table.productid, product.weight
FROM table1
INNER JOIN product
ON table1.productid=product.productid
where table1.box = '55555';

不清楚这里的问题,你只是想要总重量还是分组

SELECT table.productid, SUM(product.weight) weight
FROM table1
      INNER JOIN product
      ON table1.productid=product.productid
where table1.box = '55555'
Group By table.productid

我会给出总数。

我读了它,因为你想要那个盒子的重量和每个产品的行数。我可能错了,但如果不是的话,我就错了

SELECT Sum(product.weight)
FROM table1
INNER JOIN product
ON table1.productid=product.productid
where table1.box = '55555';

这正是我需要的,谢谢
SELECT Sum(product.weight)
FROM table1
INNER JOIN product
ON table1.productid=product.productid
where table1.box = '55555';
SELECT table1.productid, product.weight, SUM(weight) Over(PARTITION BY table1.box) AS SumWeights
FROM table1
INNER JOIN product
ON table1.productid=product.productid
WHERE table1.box = '55555';