我正在尝试列出要盘点的库存清单,前提是该商品在过去 2 个月内有销售:我正在使用 Pervasive SQL,它是一个 BusinessVision 表。此查询有效,但我不知道如何聚合以显示一项:
SELECT "INVENTORY"."CODE", "INVENTORY"."INV_DESCRIPTION",
"INVENTORY"."BVSTKUOM", "INVENTORY"."INV_COMMITTED",
"INVENTORY"."ONHAND",
"SALES_HISTORY_HEADER"."IN_DATE"
FROM "INVENTORY" INNER JOIN "SALES_HISTORY_DETAIL" ON "SALES_HISTORY_DETAIL"."CODE" = "INVENTORY"."CODE" INNER JOIN "SALES_HISTORY_HEADER" ON "SALES_HISTORY_HEADER"."NUMBER" = "SALES_HISTORY_DETAIL"."NUMBER"
where "INVENTORY"."PROD" like 'A6O%' AND "SALES_HISTORY_HEADER"."IN_DATE" > '20090731'
行。这个查询会给我一个零件号的重复结果,有不同的日期。我只想让每个零件号出现一次,前提是它在过去 2 个月内售出。例如:
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090810
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090811
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000 20090812
我宁愿简单地这样:
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
下一行是下一个产品。我怎样才能做到这一点?
一些答案后编辑的部分:感谢您对 DISTINCT 的建议。我不知道为什么它会重复结果。查看(部分)查询结果(不包括“SALES_HISTORY_HEADER”。“IN_DATE”:
CODE INV_DESCRIPTION BVSTKUOM INV_COMMITTED ONHAND
--------------------------------------------------------- --------------- ----------
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 180.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
当使用 GROUP BY 或 DISTINCT 时,我得到以下结果:
CODE INV_DESCRIPTION BVSTKUOM INV_COMMITTED ONHAND
--------------------------------------------------------- --------------- ----------
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 50.00000
A6001-O15NP HP 700-101-O White 15" NP yds 0.00000 180.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 0.00000
A6001-O15P HP 700-101-O White 15" Perf yds 0.00000 915.00000
我希望只有 2 行,即 180 和 915 行。