查询没有关键字段的表格

huangapple go评论64阅读模式
英文:

Querying a table with no Key field

问题

我们有一张表,存储了按分支存储的零件编号的销售历史记录。零件号可以存在于一个或多个分支中。列包括当前月份和前三个月份。我需要编写一个SELECT查询,以列出所有在所有分支中都没有销售历史记录的零件号。使用我提供的示例数据,我的查询应该返回Part# 56789,但不返回Part # 12345,因为它在SalesHist02列中有销售记录。我应该指出,我们实际的表格有超过29万个唯一的零件编号,以及超过130万行。谢谢提前。

英文:

We have a table that is storing Sales History for Part numbers by Branch. Part #s can exist in one, or many Branches. Columns include the Current month, and 3 previous months. I need to write a SELECT query that will list all the Part #s that have zero Sales History in ALL Branches. Using the sample data I provided, my query should return Part# 56789, but not Part # 12345, as it has sales in the SalesHist02 column. I should note that our actual table has over 290K unique part numbers, and over 1.3 million rows.
Thanks in advance.

查询没有关键字段的表格

答案1

得分: 0

基于您当前的描述和示例输出,您可以使用HAVING子句:

select partno
from sales
group by partno
having sum(saleshistcurrmo + saleshist02 + saleshist03 + saleshist04) = 0
英文:

Based on your current description and sample output, you can use the HAVING clause:

select partno
from sales
group by partno
having sum(saleshistcurrmo + saleshist02 + saleshist03 + saleshist04) = 0

huangapple
  • 本文由 发表于 2023年3月21日 03:06:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定