从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';