英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论