473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Duplicate Counts

124 100+
My database has loan data where the loans are grouped by Month/Year and there are duplicates for most loan numbers based on the LoanNumber field. The table has multiple Month/Years and I need to somehow group the data as follows:

"Unique Loan Numbers: SUM(X, Y, Z)

Loans with 1 record: X (where X equals all unique loan numbers with one row of data)
Loans with 2 records: Y (where Y equals all unique loan numbers with two rows of data)
Loans with 3 records: Z (etc.)"

How does one group by Month and get a count of dupes for each distinct loan number? I'm not sure where to start. Any help is much appreciated.
Sep 4 '14 #1
3 1268
zmbd
5,501 Expert Mod 4TB
Something simple like this should work I would think?

Expand|Select|Wrap|Line Numbers
  1. SELECT [loan], Count([dateissued]) AS CountOfdateissued
  2. FROM Table4
  3. GROUP BY [loan];
[edit added the following data table]
Expand|Select|Wrap|Line Numbers
  1. [PK]   [loan]       [dateissued]
  2. 1        a1         09/01/2014
  3. 2        b2         09/02/2014
  4. 3        b2         09/03/2014
  5. 4        c3         09/04/2014
  6. 5        c3         09/05/2014
  7. 6        c3         09/06/2014
  8. 7        d51        10/01/2014
  9. 8        e62        10/02/2014
  10. 9        e62        10/02/2014
  11. 10       f73        10/03/2014
  12. 11       f73        10/03/2014
  13. 12       f73        10/03/2014
  14. 13       g89        10/11/2014
  15. 14       g89        10/11/2014
  16. (...)  (...)       (...)
  17. 20       g89        10/11/2014
  18. 21       g89        10/15/2014
Running the aforementioned query should return:
(just for ease, loan 1 has 1 entry, 2 = 2, 51 = 1 etc)
Expand|Select|Wrap|Line Numbers
  1. [Loan]   [Countofdateissued]
  2. a1                      1
  3. b2                      2
  4. c3                      3
  5. d51                     1
  6. e62                     2
  7. f73                     3
  8. g89                     9
Sep 4 '14 #2
BikeToWork
124 100+
Thanks for the code Mr. Z. That's a good start and it gives me the number of dupes for each loan number, but they want to have the number of loans where there is no dupes, 1 dupe, 2 dupes, 3 dupes, etc, etc, ad nauseum. Could I just make another query based on the dupes query grouped by month and count of dupes?
Sep 4 '14 #3
zmbd
5,501 Expert Mod 4TB
I'll go back and add the recordset... (^_^)

Now take a look at what the query returns.
It gives you the number of associated records in the table...

so to answer your subsequent question:
loans where there are no dupes, === Loan A1, D51
1 dupe, === b2, e62 (or two associated records each)
2 dupes, =?= c3, f73 (has three records - 1' + 2'')
3 dupes, ==== didn't make one for that
etc === g89 === which has 9 records... 1' + 8''

Notice, the query doesn't take into account the dates as identifiers as we're grouping on loan only, so for B2 the two different dates return 2 records count just the same as the two dates for E62 which are the same date... return 2 record counts.


Mind you, I don't know your dataset
Sep 4 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Steven Bethard | last post by:
I have a list of dictionaries. Each dictionary holds counts of various 'words', e.g.: py> countdicts = I need to select dicts with the constraint that the number of each 'word' totalled...
0
by: Andres | last post by:
Hi, i have this questions: 1 - How can i create user counts in Windows with C#? 2 - How can i set permissions for the counts with C#? 3 - How can i start an application with one of the created...
5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
1
by: Robert | last post by:
How can I query an existing table and update a field in each record in the table with the occurrence count of each record e.g. update field to 1 (= first record occurrence), update field to 2 for...
6
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
7
by: ucfcpegirl06 | last post by:
Hello, I have a dilemma. I am trying to flag duplicate messages received off of a com port. I have a software tool that is supposed to detect dup messages and flag and write the text "DUP" on...
11
by: dhutton | last post by:
Hey Everyone - What would be the best way to sort data that has common fields? Here is my example: Feature Date Order Number ===========================================...
3
by: rhonda6373 | last post by:
Is it possible to have counts from two different tables in one query? I tried this and it worked, but I have duplicate rows with the same count numbers.
1
by: lilmisspink07 | last post by:
Hello, I am trying to pull a list of sample counts by test. I only want 1 row per test result so that I can build a report in Cognos showing the rate of a particular result as a percentage of the...
24
by: MLEBL | last post by:
I'm creating a scheduling application for a hospital department that indicates when they've exceeded the minimum required staff for a particular shift. I have a table keeping track of the count and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.