顺序组号查询结果 [英] sequentially group number query results
问题描述
我搜索了论坛,发现了一些非常接近于帮助我正在尝试但不完全正确的事情。
我需要在访问查询中按顺序对结果进行分组编号,就像通过PUR_DATE和CSCODE进行分组一样 - 但我不想对查询进行分组...这样一个字段 ; GRP"会产生这样的结果:
PUR_DATE CSCODE GRP
1/5/2009 1456 1
1/5/2009 1456 1
1/5/2009 1456 1
1/5/2009 985 2
1/5/2009 985 2
1/5/2009 985 2
1/6/2009 5684 3
1/6/2009 5684 3
1 / 6/2009 2310 4
1/6/2009 2310 4
1/6/2009 2310 4
2009年1月7日985 5
1/7/2009 985 5
有什么想法吗?
I searched the forum and found something very close to helping me with what I''m trying to do but not exactly.
I need to sequentially group number the results in an access query as if by grouping by PUR_DATE AND CSCODE - but I do not want to group the query... So that a field "GRP" would yield results like this:
PUR_DATE CSCODE GRP
1/5/2009 1456 1
1/5/2009 1456 1
1/5/2009 1456 1
1/5/2009 985 2
1/5/2009 985 2
1/5/2009 985 2
1/6/2009 5684 3
1/6/2009 5684 3
1/6/2009 2310 4
1/6/2009 2310 4
1/6/2009 2310 4
1/7/2009 985 5
1/7/2009 985 5
Any ideas out there?
推荐答案
您是否希望为重复项分配相同的GRP编号?编写代码并不困难,但纯SQL可能有用。要考虑一下,但我怀疑其中一位专家可以做到。
So you want duplicates to be assigned the same GRP number? Not too difficult to code, but it may be possible with pure SQL. Going to think about it, but I suspect one of the experts can do it.
是的,如果我理解正确的话。 CSCODE是客户编号。 PUR_DATE是购买日期。同一天的多个CSCODES意味着客户购买了多个项目。所以我确实希望重复的CSCODE具有相同的GRP编号,只要它在同一天。客户将返回并在多个日期进行购买,但是......如果它是相同的CSCODE,但在不同的日期,它将具有不同的GRP编号。我希望GRP编号对于pur_date AND cscode是唯一的。
Yes, if i understand you correctly. CSCODE is a customer number. PUR_DATE are purchase dates. Multiple CSCODES on the same date means that customer purchased more than one item. So I do want duplicate CSCODEs to have the same GRP number as long as it is on the same date. A customer will come back and make a purchase on multiple dates though... so If its the same CSCODE but on a different date it will have a differnt GRP number. I want the GRP number to be unique to the pur_date AND cscode.
这是为了什么?你只是想能够
SELECT * from myTable WHERE GRP = n
而不是
SELECT * FROM myTable WHERE PUR_DATE = x和CSCODE = y
这实际上违反了表格规范化。
What is this for? Do you just want to be able to
SELECT * FROM myTable WHERE GRP = n
instead of
SELECT * FROM myTable WHERE PUR_DATE = x and CSCODE = y
This actually violates table normalization.
这篇关于顺序组号查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!