Queries :: Count Occurrences While Keeping Duplicates?

Sep 9, 2013

I'm trying to create ONE query which would fetch me the number of occurences on a particular value in a field while keeping duplicates.

For instance let's say i've got the following table

Color......Value
Red.........5
Red.........8
Orange....1

Then i would like to have the following result from my query

Color.........Value.......CountOfColor
Red............5..............2
Red............8..............2
Orange.......1..............1

I know i could achieve this by creating a view first. For instance by saving this expression as qryCountOfColors

Code:
SELECT tblColors.Color, Count(tblColors.Color) AS CountOfColor
FROM tblColors
GROUP BY tblColors.Color;

And then make the following query

Code:
SELECT tblColors.Color, tblColors.Value, qryCountOfColors.CountOfColor
FROM tblColors INNER JOIN qryCountOfColors ON tblColors.Color = qryCountOfColors.Color

However I'm woundering wheter or not I could achieve it without creating the qryCountOfColors.I'm myself into a mental meltdown . I've been playing with the idea of creating of creating a subquery to achieve this but im unable to get to work

Code:
SELECT tblColors.Color As BANANA, tblColors.Value, (SELECT Count(tblColors.Color) AS CountOfColor FROM tblColors GROUP BY tblColors.Color HAVING (((tblColors.Color)=BANANA))) AS Expr1
FROM tblColors;

View Replies


ADVERTISEMENT

Queries :: Count Occurrences Of A Company In 3 Separate Tables?

Dec 18, 2014

I am trying to count the number of times a client has engaged with our company. I have a company table, a reservation table, a rapid prototyping table and a project table. There is a one to many from the company table to each of the other 3 tables as can be seen in the attached picture.

Is there an easy way, in a single query, to list unique company names that exist in 1 or all of the 3 tables?

View 2 Replies View Related

Queries :: Count Duplicates By Month?

Jun 4, 2015

I want to be able to find duplicate numbers in the "claim #" field that exceed 20 within the "date of service" field for a month. I have a date box which allows me to select data from only one month at a time or all. What I'd like to be able to do is group the results by month. Currently it is only matching numbers by day not month.

SELECT HMR.[Claim #], Count(HMR.[Org #]) AS Total, HMR.[Date of Service], Count(HMR.[Date of Service]) AS [CountOfDate of Service]
FROM HMR
GROUP BY HMR.[Claim #], HMR.[Date of Service]

[Code] ......

View 14 Replies View Related

Removing Duplicates While Keeping A Running Total

May 10, 2005

High everyone I've had a look around the FAQ's and other threads but haven't been able to find what I'm looking for.

I have a table that contains two fields, one being 'part number' and the other being 'quantity'. Unfortunately there are multiple duplicate 'part numbers'. I am looking at keeping only one instance of the duplicate 'part numbers' but at the same time I want to add the 'quantities' together to keep a running total.

For example:

Before
Part Number Quantity
a1 1
a2 2
a3 2
a1 1
a2 1
a1 4
a1 1

After
Part Number Quantity
a1 7
a2 3
a3 2

Any help would be greatly appreciated.
Cheers

View 5 Replies View Related

Removing Duplicates But Keeping Lastest Record

Dec 23, 2014

i have queries and tables with several duplicated "username" records. What should i do to remove the record with a smaller value of "win/loss" and keep the duplicated "username" with a bigger value of "win/loss".

View 1 Replies View Related

Queries :: Count Duplicates Based On Set Of Criteria

Aug 27, 2013

want my query to count only records that are not duplicated based on a set of criteria.I have a table with customer IDs and Call dates and the employee ID. I want a count of the call dates for each customer ID for each employee. However I only want to count as one occurrence if multiple calls happened on the same day. For example

Cust_ID Call_Dt
12315 8/1/2013
12315 8/1/2013
12315 8/1/2013
14253 9/1/2013

Customer ID 12315 would only count a 1 call entry instead of 3 for the date of 8/1/2013

View 3 Replies View Related

Domain Aggregate Functions To Count Occurrences Of Specific Value In Field

Jul 8, 2012

i need domain aggregate functions to count the occurrences of specific value in a field, and when it exceeds 1, display null. or 'group by' subqueries with count() to see if you should populate the field or not.

View 3 Replies View Related

Queries :: Table A And B - Counting Occurrences Of ID

Jan 10, 2014

I have a Table A that is a list of ID's. In table B, each ID (from A) could appear multiple times, or not at all.

How do I get a count of how many times each ID in Table A appears in Table B? ie. 0 or 1 or 5 or whatever.

View 4 Replies View Related

Queries :: Counting Occurrences Of P - Summary Column In Crosstab Query

Feb 18, 2014

I need to add a column to a crosstab query that counts all of the occurrences of "P" in a particular row in the crosstab query. Basically "P" stands for "Present" and I need to know how many days each employee was present for his/her shift. The SQL for the crosstab query is as follows:

PARAMETERS [Forms]![frmDashboardReports]![txtStartDateAndTime] DateTime, [Forms]![frmDashboardReports]![txtEndDateAndTime] DateTime;
TRANSFORM First(tblAttendance.AttendanceCode) AS FirstOfAttendanceCode
SELECT tblAttendance.EmployeeName
FROM tblAttendance
WHERE (((tblAttendance.AttendanceDate)>=[Forms]![frmDashboardReports]![txtStartDateAndTime] And (tblAttendance.AttendanceDate)<=[Forms]![frmDashboardReports]![txtEndDateAndTime]))
GROUP BY tblAttendance.EmployeeName
PIVOT Format([AttendanceDate],"Short Date");

This returns an "AttendanceCode" against each employee against each day in the specified time period. I just need to be able to "sum" those codes in a column.

View 3 Replies View Related

Queries :: Access 2007 - Query To Pull Fri / Sat / Sun Occurrences In A Specific Month?

Jul 7, 2014

Access 2007 query that has a specific date range between #6/1/12014# and #7/1/2014# returns the date I need. How do I now get it to pull just occurrences on Fri Sat and Sun of the month of June?

View 5 Replies View Related

Count Function Excluding Duplicates

Dec 2, 2004

What expression do i use to count the number of patientID when there are duplicates (ie patient has come back for more than one visit but I just want to know the number of patients who visited (not how many times))

Count([patientID]) doesn't exclude duplicates

View 3 Replies View Related

Modules & VBA :: Loop Through A Table Count Duplicates Only Once

May 13, 2015

I am trying to loop through a table and count the duplicate records only once. Please see the attached file.

1) In the test table, I want to loop through all pt_accts.

2) In the countable column, if an acct repeats, I essentially just want to put "1" in one of the records. For the non-repeating accts, putting in a 1 is sufficient. Basically, I just don't want to count the duplicate ones multiple times.

In the example, acct "aaa" repeats, but there is just one "1" in the countable column. "eee" repeats as well, but there is just one "1" and the rest is 0.

Is this possible via VBA?

View 14 Replies View Related

Queries :: Excluding Records - Keeping Nulls

May 2, 2013

I have a table of around 6000 records comprising 4 fields (A,B,C,D).

- Each field can contain numbers or Nulls.
- Each record can comprise all numbers, a mixture of numbers or Nulls, or all Nulls.

I'd like to build a query that excludes all records that contain any number from a small list of numbers.

This sounds very simple but I am having problems when trying to include records that have Null's in my query output.

For test purposes I tried to exclude all records that contain the numbers 1 or 9 (these numbers can be present in any field).

This works perfectly, in isolation, on Field A (i.e. 1 or 9 but not Null are excluded from field A):

Code:
WHERE Table.A Not In (1,9) OR Table1.A Is Null;

When I try to copy the above, referencing fields B-D, I run into problems - no matter how I try to alter the Boolean operators.

View 2 Replies View Related

Keeping Focus On Main Form While Queries Are Running

Jul 23, 2005

I'm sure there is a simple solution - but everything I have tried hasn't worked.
I have a command button on my main form that opens up a popup form. On the popup form the user makes various selections and clicks on another command button(on the popup form). That button is linked to a macro - that runs several queries.

The problem I am having is when the macro starts to run - the main form is maximized again (so now it doesn't take up the full screen - just a part of the screen) and some of the queries start flashing in front of the form.

I know how to maximize the form once the popup form closes - that's not a problem. I just cant figure out how to keep the focus on the main form and in front of all the queries as they are running.

View 2 Replies View Related

Queries :: Keeping Records Of GST Transactions - How To Do Calculations In Query

Apr 5, 2013

I am trying to keep records of GST transactions.

I have a problem in figuring out how to do calculations in a query.

How to have the calculation in the attached MDB and Document for field #105_SubTotal and the field #115_PaymentEnclosed.

View 7 Replies View Related

Queries :: Using Count And MIN Together To Retrieve Only MIN Record With Count

Aug 16, 2015

I have a table that has 5M+ accounting line entries. Below is an example of one accounting journal in the table.

BUSN_UNIT_IJRNL_DJRNL_ICNCY_CMONY_A
CB0014/07/20140002888269323AUD16797
CB0014/07/20140002888269323AUD-16797
CB0017/07/20140002888269323AUD16797
CB0017/07/20140002888269323AUD-16797

The journal ID above was an accounting entry, debit $16,797 and credit $-16,797. because it was entered as a reversing journal in the system, the table has captured the Journal ID with 2 dates. For my purpose i only want the one date (MIN) date, the total amount of the journal (either the debit or credit amount 16,797) and the total number of lines the journal ID has so in this instance I want the count to be 2 and not 4.

Right now this is what i get

BUSN_UNIT_I JRNL_I CNCY_C SumOfMONY_A CountOfJRNL_I MinOfJRNL_D
CB001 0002888269 AUD 0 4 4/07/2014

This is the output i would like

BUSN_UNIT_I JRNL_I CNCY_C SumofMONY_A CountofJRNL_I MinOfJRNL_D
CB0010002888269323 AUD16797 2 4/07/2014

Im thinking with the total sum because theres debits and credits is there a way to do the absolute value of the journal MONY_A then divide by 2?

current SQL
SELECT [One Year Data Lines].JRNL_I, [One Year Data Lines].CNCY_C, Count([One Year Data Lines].JRNL_I) AS CountOfJRNL_I, Min([One Year Data Lines].JRNL_D) AS MinOfJRNL_D, [One Year Data Lines].BUSN_UNIT_I, Sum([One Year Data Lines].MONY_A) AS SumOfMONY_A
FROM [One Year Data Lines]
GROUP BY [One Year Data Lines].JRNL_I, [One Year Data Lines].CNCY_C, [One Year Data Lines].BUSN_UNIT_I
HAVING ((([One Year Data Lines].JRNL_I)="0002888269") AND (([One Year Data Lines].CNCY_C)="aud"));

View 9 Replies View Related

Queries :: Rolling 12 Month Query - Keeping Track Of Orders Placed For Given Part Number By Month

May 5, 2014

I am trying to create a database that will keep track of the orders placed for a given part number by month. Currently, my table houses the part number, and the ordered amount for the past three years by month (there are thirty-five columns for every part). My column headings are ORDER_MAY_2013, etc. I would like to set a query up that will look at the column headings and pull the amounts ordered for each part for the past twelve months. In other words, I have three years of data in my table. In my query, I just want one year. However, I don't want to have to rewrite the query every month so that it will pick up the new data. Is there a way to accomplish this?

Is there a better way to build this database? I thought about just have four columns in my table - PART_NUMBER, ORDER_MONTH, ORDER_YEAR, ORDER_AMOUNT. The only problem there, is that every part (there are about 450 parts) would have to be listed 35+ times. That seemed too redundant to me, so I built the table this way. However, now I am having trouble querying against it.

View 2 Replies View Related

Counting Occurrences

Sep 1, 2007

I have a table which is basically a calendar containing the columns (i) date, (ii) special info relating to that date (iii) morning volunteers and (iv) afternoon volunteers.

In the "Morning Volunteers" there are up to two names with sometimes a first name, sometimes an initial but always a family name.

The same is true for the "Afternoon Volunteers".

What I want to do is, using the Family name, to find out how many mornings/afternoons each of the volunteers has manned the Visitor Centre.

As I am new to Access I have no idea whether this is possible and, if so, how to do it.

I can do it by exporting the table to Excel but this is very clumsy and time consuming

I am using Vista and Access 2003.

View 1 Replies View Related

Queries :: Delete Duplicates In Row Of Data

Feb 10, 2014

I need to delete duplicate rows (or create new table without them) but the duplicate is not the entire row of data.

Date Time LeagueMatchingId League HomeMatchingId HomeName AwayMatchingId AwayName
HomeScore AwayScore HomeRedCardCount AwayRedCardCount FTOU FTOverOdds FTUnderOdds
20121202 10/02/2014 20:34:02 17 FRANCE LIGUE 1 147 Lorient 154 Toulouse 0 0 0 0 1.5 0.88 -0.98
20121202 10/02/2014 20:34:02 17 FRANCE LIGUE 1 147 Lorient 154 Toulouse 0 0 0 0 1.5 0.88 -0.98

[Code] .....

In this example I am only interested in the first and last rows, since the ones in between have the same data in the last few columns. They are not true duplicates since the time stamp for each is different.

Currently thinking I need to compare each and every row to the prior row in VBA and delete if criteria match.

View 4 Replies View Related

Queries :: Finding Duplicates Using Last Name And First 3 Letters?

Apr 2, 2014

I need to create a query that will pull duplicate names out of my db.

I would like it to pull all names that have:

duplicate LastName and duplicates of the first 3 letters of the FirstName.

For example, if I had the names:

Bland, Abe
Brown, Abe
Brown, Bill
Buster, Jon
Buster, Jonathon

I would like my query to return only Buster, Jon and Buster, Jonathon.

View 4 Replies View Related

Queries :: Matching Values Without Duplicates

Oct 23, 2013

I'm looking for a way to grab values from one table that match a criteria, and append them/update them to another, but only grab one value once. Example:

Part ID ---- Profile Profile ID ---- Locations
Part1 - Profile 1 Profile 1 ---- Location 1
Part2 - Profile 1 Profile 1 ---- Location 2
Part3 - Profile 1 Profile 1 ---- Location 3

I have a database of parts that fit in certain profile sizes. Each profile size has multiple open locations. I need a query to grab a location, assign it to a part, grab a new location, assign it to the next part, etc, without assigning duplicate locations to different parts.

Right now, I'm doing this by using the First/Last aggregate functions, marking them as used, and looping it again and again until all have unique locations. Is there a better way to do this?

View 8 Replies View Related

Queries :: Identify Duplicates With Three Criteria

Apr 5, 2013

I have the following columns in my table 'Catalogue'.

Contract_contractitem
contract
Supplier name
Item number
Short description
Long description

I need to identify duplicates if the short desciption is the same, long desciption is the same but the item number is NOT the same.

e.g.

4700000551_978, 4700000551, FISHER SCIENTIFIC BIOTECH LINE ApS, mbp-6014, 0,2 ml PCR Tube, Hotstart, wax bead, NS, 0,2 ml PCR Tube, Hotstart, wax bead, NS 96 tubes/pack, 10 packs/Cs

4700000551_977, 4700000551, FISHER SCIENTIFIC BIOTECH LINE ApS, mbp-6010, 0,2 ml PCR Tube, Hotstart, wax bead, NS, 0,2 ml PCR Tube, Hotstart, wax bead, NS 96 tubes/pack, 10 packs/Cs

View 4 Replies View Related

Queries :: Deleting Duplicates Without Primary Key?

Nov 4, 2013

I bounced into a big problem with Access 2010 where I cannot seem to be able to remove duplicates from a table containing millions of entries midway through a series of queries.

The table is formed like this:

Date - Serial Number - Reading 1 - Reading 2 - Reading 3
30.7.2013 - 1122334455 - 12345 - 987654 - 654321
30.7.2013 - 1122334466 - 12345 - 987654 - 654321
29.7.2013 - 1122334455 - 12210 - 987654 - 643210
29.7.2013 - 1122334455 - 12210 - 987654 - 643210
29.7.2013 - 1122334466 - 12344 - 986013 - 453213

As you can see, there are some rows which contain exact duplicates and some are a bit different. I wish to remove those fields with exact duplicates and only the duplicated fields. Running "Find duplicates" in Access gives me about 250,000 rows with such data.

I've tried a few options already:
- I cannot use the date as primary key as there are several serial numbers. I cannot use serial numbers as primary key, because there are several dates. Using reading value as primary isn't an option either.
- Microsoft says I should mark all duplicate values with an x and then make a delete query to get rid of all the x-marked rows. For 250,000 duplicates, that's a bit too much manual 'x-ing'.
- If I do a delete query using the Find Duplicates query as a base, it removes all 250,000 entries from that table, instead of just the 125,000 which had a duplicate elsewhere in the table.
- If I make a query which identifies duplicate data and gives me just one row for each duplicate, the delete query still deletes both entries from the original table.
- I could make a new query which would have only unique values using Totals as criteria (for instance, using First for the Date-column). However, this still leaves the duplicate values in the original table. Note that this database is already 800 MB large and new data is imported once a week, for the next decade or so. I cannot have a table get duplicates every week and leave it there.
- If I make a macro which would create the unique values table first and then deletes the old table, what happens next week when I try to import new readings? I would need to make a new macro each time I try to import new data as the table names change. Or is there a way to first run the unique numbers out, then replace the original table with the new one? With a 800MB database, this would put me dangerously close to the 2GB size limit. I wouldn't be able to use this as a part of a macro, as the database would have to do Compact & Repair each time it deletes the original table, midway through a longer series of queries.
- Having duplicates removed from the original import isn't an option either, as it comes in as a overriding excel sheet for the past 3 months, once a week.

As you can see, it's quite a pickle getting the duplicates out of the original table. This is just a small part of a very long macro, which takes about 15 minutes to complete, but due to duplicates the database is getting way too large.

View 9 Replies View Related

Queries :: Hide Duplicates From Query?

Aug 1, 2013

I have a query showing duplicates, I want to hide the duplicates that have a null value in one of the rows..

Trunc_Name M_UNDERLYIN MaturityDate Duration SumOfSumOfM_VEGA Volatility
SPX P1400 DEC13 INX 21-dec-13 4,766666667 -108 812,00 0,22437
SP6652 CALL SP6652 04-okt-17 50,86666667 124 376,00 0,21
SP6652 CALL SP6652 04-okt-17 50,86666667 124 376,00

Here's an example of the a duplicate, all 4 first rows are duplicates, but the last value is null for the last duplicate. I want to hide the one the duplicate that has null value!

View 4 Replies View Related

Queries :: Total Excluding Duplicates?

Aug 30, 2013

I have a table with the following fields:

Customer
Month
Qty
Unit Price
Extended Price

I want to know, by month, what the total extended price is for all customers. But some customers appear more than once in a month. So I also want to know the total extended price for the month, but I only want to include the extended price for each customer once, using only the record with the highest unit price (or extended price, qty for each customer is consistent), and ignoring additional records with the same customer in that month.

I am an excel user, and I could quickly do this with pivot tables... but I have too many records for Excel to handle this efficiently (it just keeps crashing!), so I thought I'd move to access... but I don't know how to use access! So I may need a little hand-holding here.

View 10 Replies View Related

Queries :: Join Two Tables With Duplicates

Oct 19, 2013

I am trying to combine two peculiar tables in Microsoft Access and have been unable to do so even after doing a lot of brainstorming and searching on the internet.

The two tables are spend and export
Spend
+-------------+--------+-------+-------+
| Country | Metal | Month | Spend |
+-------------+--------+-------+-------+
| China | Iron | Jan | 100 |
| China | Iron | Feb | 200 |
| China | Iron | March | 300 |

[code]...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved