Queries :: Find Largest Value For Each Row?
Jul 19, 2014
I would like to find the largest value for each row in a query. I have a query with several fields, each field has an expression that produces an integer.
Max and DMax seem to pertain to the values in a single field; I need to evaluate values from multiple fields in a single row.
I keep seeing 'range' mentioned but I have yet to see any examples of evaluating a series of data like 'col1;col2;col3' or anything remotely similar.
View Replies
ADVERTISEMENT
Jun 4, 2014
I have a table of logged entries. Each record has a date field (ValueDate) and an account identifier field (AccountID)
I also have a table of rates. Each record has the same account identifier field (AccountID), a date field (EffectiveDate) and a rate field (BankRate)
Entries can be logged for any given ValueDate. But there may or may not be a corresponding EffectiveDate in the rates table.
I need to write a query that will return all of my logged entries and the largest EffectiveDate which is on or before the ValueDate (as well as the BankRate corresponding to that EffectiveDate)
This is as far as I've gotten but it returns multiple records for each logged entry. I need one record per logged entry.
Code:
SELECT tblLoggedEntries.EntryID, tblLoggedEntries.AccountID, tmp.BankRate, MAX(tmp.EffectiveDate) AS EffectiveDate
FROM tblLoggedEntries
LEFT JOIN
(SELECT tblRates.AccountID, tblRates.BankRate, tblRates.EffectiveDate
FROM tblRates) AS tmp ON tblLoggedEntries.AccountID = tmp.AccountID
WHERE tmp.EffectiveDate<=tblLoggedEntries.ValueDate
GROUP BY tblLoggedEntries.EntryID, tblLoggedEntries.AccountID, tmp.BankRate
View 11 Replies
View Related
Dec 4, 2013
I'm trying to create a query that will compare the data in 3 fields in a record, choose the largest (I also have a criteria to order by if more than 1 field has the same entry and it's the largest of the 3), and then group by that.The fields I will need are as follows:
PRODUCT table:
ProductName
Chemical
ChemicalAbstract
PhysicalState
NFPAHealth
NFPAFlammability
NFPAReactivity
qryQuantityOnHand query (which doesn't link directly to the PRODUCT table, it links through associations with other tables):QOH...I will eventually need information from another table for the final reports, but I don't think it has to be included in this query.
The fields NFPAHealth, NFPAFlammability, and NFPAReactivity each may be 0, 1, 2, 3, or 4...I need to ignore blanks; if 1 of the above fields is blank, they will all be blank.For any record, I need to compare the number in those 3 fields to each other, and choose the largest number and group by that rating.
In other words, if the largest of the 3 numbers is a 3 in the NFPAFlammability field, all those products need to be grouped together.If the same number appears in at least 2 of the fields, the order that determines the grouping is: Flammability, then Health, then Reactivity..Ultimately the report will be grouped as follows:
Flammability
Rating 4
Product 1
Product 2
Product 3
Rating 3
Product 1
Product 2
Product 3
Rating 2
Product 1
Product 2
Product 3
Health
Rating 4
Product 1
Product 2
Product 3
[code]....
and each of the groups will be sub-totalled.I'm stumped at trying to create the query in the first place.The added aggravation here is that we are dealing with 23 stores, each with their own mix of products. I have another table that contains the information about which products are in which store.
View 4 Replies
View Related
Jan 27, 2004
Hi, I'm trying to build an expression that will allow me to find the second largest (third largest, fourth largest, etc...) value for a given field. I'm tracking the sales of a company and the database has over 900 customers. I know using the Max fuction will get me the largest value, but how do I find the second largest value?
I've already tried this:
DMax (total_sales, customer_sales, Not Max (total_sales) )
where:
"total_sales" is the name of the field (column)
"customer_sales" is the name of my table
I'd appreciate any help. I know I got the idea right but I'm getting confused with the order of the functions.
Thanks!
Mike
View 5 Replies
View Related
Jun 29, 2006
So I have another how do i get a form feild to automatically pickup the largest value. it is for an auto number and i want it to show only the last record that was created so it has to be set to show the largest number.
any help would be great.
View 1 Replies
View Related
Sep 24, 2007
I'm fairly new to access, but I thought this was simple!!! I want to querry a column/field in a database table called Quote # simply to return me the largest number in that column. I then want to use that number and add 1 to it each time I start a new record....
Any help appreciated
View 1 Replies
View Related
Oct 1, 2006
Hi, newbie question.
I have an existing select Query, that has a field of dates. I want a new select query based on that source that shows all records except for the one with the largest value date. There will be no duplicate dates. I tried:
SELECT Q_Tasks_Accs.End AS NotLatestEnd
FROM Q_Tasks_Accs
WHERE (((Q_Tasks_Accs.End)<(Max([Q_Tasks_Accs].[End]))));
but when I run the query I get error message:
"Cannot have an aggregate function in WHERE clause(Q_Tasks_Accs.End)<(Max([Q_Tasks_Accs].[End]))"
I clicked on Help but did not understand what it said. So any help from here would be appreciated.
Thanks
View 2 Replies
View Related
Oct 4, 2014
I need to find best combination using Loop to count "NumerOfSheets" To achieve smallest possible number from among the largest. Taking into account additional blocks to allocate. My table before running code looks like
Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2
2 B 200 1
3 C 100 1
At the beginning I was using code (I had no additional blocks):
Code:
Dim recIn As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tbl1;"
Set recIn = CurrentDb.OpenRecordset(strSQL)
While Not recIn.EOF
[Code] ....
It worked! But now I have new field in my main form "Forms!frmGlowny!FreeBlocks" Where I keep number of blocks to allocate (additional blocks which I can allocate in the column "Blocks"). This filed is count by another code. What is important now, this is positive integer (usually no more than 20). I need find best way to allocate my free blocks. What is best way? - The largest number from "NumerOfSheets" should be as small as possible.
Suppose that this example Forms!frmGlowny!FreeBlocks = 1 (so it's very simple example). So Let's find where I should allocate my 1 free block (I need do it by hand, because I don't have a code:/).
Combination 1
Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 3 117
2 B 200 1 200
3 C 100 1 100
Combination 2
Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2 175
2 B 200 2 100
3 C 100 1 100
Combination 3
Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2 175
2 B 200 1 200
3 C 100 2 50
The smallest possible number from among the largest is in the combination No. 2 (because the largest = 175 so it is smallest from all largest numbers of combinations), so now I know that my 1 free block should be added to B order to column "Block". It's very simple example because I have only A;B;C oders and 1 block to allocate. But When I will have e.g orders: A;B;C;D;E;F;G;H and 14 blocks to allocate count by hand will be terrible...
View 14 Replies
View Related
Aug 1, 2014
I have been working on a simple data base for some time now (beginner level) and am still trying to improve it. I would like to do something but before that I would like to have your opinion to know if it is even possible?I have a query QryMainReport:
Start Date/Time
End Date/Time
Employee
At the moment this is what the format of my report looks like (I removed other unnecessary fields):
StartTime----------EndTime---------------Employee
12/06/2014 01:00--12/06/2014 03:00------John Smith
12/06/2014 04:00--12/06/2014 06:00------Jane Doe
13/06/2014 02:00--13/06/2014 05:00------John Smith
13/06/2014 08:00--13/06/2014 08:00------Jane Doe
I would like to do as a report. (Dates would always be from Sunday to Saturday). I am not sure it is possible to do that. I suppose first it would mean:I would have to do a query to separate the times from the dates?I would have to find a way for Access to find the unique dates and unique names?Does it mean I have to use cross tab queries?
View 2 Replies
View Related
May 10, 2005
Ok this might be a really stupid question, but in the quest to always make my life a little bit easier thought i would ask !
I have been asked to find the relationship between a number of tables and queries, so that this company can find out which tables and fields in tables are no longer really used, in other words how many queries and which ones is table A used in if you understand what I mean !
doing it manually means checking every query (and there are a lot !!) and seeing which table they use.. what I want to know is what is the quickest way to to this? can I do it from the table end? in others find out how many queries Table A is used in ? or do I have to go through each query individually? if this is the case my thoughts were just on copying and pasting the sql view from every query into a a word or txt doc and then doing a search /find for each table name? but if anyone has a more efficient idea on how to do this if u cld let me know !! :confused:
View 2 Replies
View Related
Apr 5, 2008
Hi am a forensics student taking a course in Database management and we use microsoft access 2003. I opened an assignment already started in 03 format, I am now running access 2007 and I need to make modifications to a previous query but I can't find the query table. how do I view my pre made queries on the 2007 version?
View 2 Replies
View Related
Aug 3, 2013
Say i have a table which contains payment information for various people - similar to this
Person Pay Date Pay Amount
User1 01/01/13 £10
User2 01/01/13 £10
User1 10/01/13 £0.00
User1 15/01/13 £0.00
I need to create a query which shows me only results for each person who has paid £0.00 more then once...
View 4 Replies
View Related
Jun 12, 2014
I would like to find the intersection of two queries. Is the SQL keyword INTERSECT supported in Access?
View 8 Replies
View Related
Jul 21, 2005
I've inherited a database with many queries (most based on a single table). There is a requirement to change the name of a few fields in the table. Is there a way to find ALL queries/reports that are utilizing the fields that need to be changed so I know what queries need to be modified?
View 3 Replies
View Related
Mar 14, 2014
I've got two tables, both are indexed by customer ID, with a series of dates against the customer ID. One has a list of all dates a customer was visited, the other is a list of dates where activity happened on the customer account
I want to get a list of the dates when the customer was visited but where no activity happened on the customer account, i.e. where there is a customer visit date on the customer visit table but no record for that date on the activity table.
How do I do that? I can find all dates where was a date was on both tables, but how to find where its on one but not the other
View 2 Replies
View Related
Feb 17, 2015
I am trying to find company matches between 2 tables. The issue I have is that the spellings on table A differs from table B.Some of the differences are minimal like "St. Annes" and "St Annes". And some really big "St. Annes" and "Annes, ST London".
View 1 Replies
View Related
May 29, 2015
I have a table 45 fields. There is a field ID. I would like to get the records where fields contains "No". I would not like to create 45 queries for each field check. how can i generate a table which shows ID, Field Name that contains value "No".
View 4 Replies
View Related
Sep 5, 2014
Trying to parse first two sections of a five section string. Now getting a SYNTAX COMMA ERROR. Th Left((([ArborID],InStr([ArborID],"-")+1,(InStr(InStr ([Arbor ID],"-")+1,[ArborID],"-")-InStr([ArborID],"-"))-1)),10)
View 14 Replies
View Related
Aug 3, 2013
I have the two tables in my access DB:
Property Information
Lease Information
I need to write a query which shows where a property does not have an associated lease, or where there is no current lease associated with it.
Property Info:
PropertyID
Address
Lease Info:
LeaseID
LeaseStartDate
LeaseEndDate
PropertyID (linked field to property table)
How to show expired / not current leases, but can't seem to show where there has never been a lease on a property.
View 4 Replies
View Related
Dec 2, 2014
I have a database with 8 years of info on customers orders. I need to find out when each customer first used our services.
View 8 Replies
View Related
Jan 16, 2014
How to find the Minimum value of a column. This is my SQL:
SELECT *
FROM tblFinalMaster
WHERE (((tblFinalMaster.OperatingDay)=[forms]![frmEnterParameters]![Combo13]) AND ((tblFinalMaster.[Checkout Order])=([Forms]![frm01ATFTieLineCheckout]![Checkout Order])+2) AND ((tblFinalMaster.[From BA_REPORT])=[forms]![frmEnterParameters]![Combo5]) AND ((tblFinalMaster.[TO BA_REPORT])=[Forms]![frmEnterParameters]![Combo3]));
The part in blue, instead of pulling a +2, I want the Minimum value. Seems simple enough.
View 5 Replies
View Related
Apr 16, 2015
I have been trying to get this to work for days and I cant get it to work correctly. I have a query that I need to search only for the records that have 12,22 and 24 so in the fields criteria I have been trying
Total: Where
Criteria: In (12,22,24)
and it works BUT it only works for the first record it finds then it seems to skip and continue to search for all records after that.
View 3 Replies
View Related
Apr 4, 2014
I am not sure if my coding is efficient or not but it takes so long to read lets say tbCOMPANY 40k records and find if values of two columns exists in tbRESULT which holds 30k records. Then if it doesn't find any records in the tbRESULT it will just insert the row otherwise an update will be executed.
What I did was:
1. Read tbCOMPANY each row using for loop
2. tbCOMPANY.FindFirst to lookup if values exists in the tbRESULT
3. If tbCOMPANY.noMatch, it will insert into tbRESULT
4. else it will update the matched row in the tbRESULT
Its been taking like over 30 minutes to process this and still ongoing and it will still keep on running. Now Access is showing as Not Responding in the task manager.., Any efficient way to do this?
View 3 Replies
View Related
Aug 8, 2014
I'm currently busy with something for my thesis as a student and I need to use Access for this. I'm not too new at access, I know how to do the very basics, let's say on the level of [if field contains *"text*", return x].
However I am struggling right now on something that shouldn't be too hard... I could do it immediately in Excel if there werent millions of rows..I have 2 tables. Table 1 regards a list of patent publication numbers (eg. WO2012024604A3) and additional data (publication date, title, etc), only the publication number matters for me now.
Code:
Table 1
publication numberWO2011085209A2
WO2011100754A1
WO2011112983A3
EP2342192A4
EP2342192A2
EP2205725A2
EP2205725A4
WO2012006540A3
WO2010008486A3
WO2012083136A1
Table 2 contains another list of patents that might cite/refer to Table 1's patents and additional data such as publication date.
Code:
Table 2
Publication Number Citing PatentsPublication Date Cited Refs - Patent
AU2001287375B2 1998-12-01 US5178882A | US4225581A | WO1998001161A2
AU2001288365B2 1990-02-24 US5967154A | WO1996039117A2 | US3699979A | US3943949A | US3838702A
AU2001288437B2 1999-03-09 US6087157A
[code]....
Now what I'd like to do is to create a third table which has for each of [Table 1].[Publication number]:
Column 2) A count of how many times the [Table 1].[Publication number] is found in [Table 2].[Cited Refs - Patent] ...
Column 3) In case a patent is cited more than once, return the [table 2].[publication Number Citing Patents] value of the earliest citing patent (so with the lowest Publication Date value).
For Column 2 I had expected it to be an easy count(iif( [Table 2].[Cited Refs - Patent] = "*"&[Table 1].[publication number]&"*")) command but apparently it's harder than that..
View 2 Replies
View Related
Apr 2, 2014
I've got 2 tables, same structure, one [T-temp-Target] holds number of training units split by module a trainee needs to finish the course, the other [T-temp-Actual] holds what they've completed so far.
Both tables have structure
TRAINEEID
MODCODE
CountOfUnits
I'm trying to find the modules that they've not done yet so I can add up the units for them, only modules that have been started are recorded in the table of what they've done [T-temp-Actual], modules they haven't started yet aren't included in it. Here's the SQL
Code:
SELECT
[T-temp-Target].TRAINEEID,
[T-temp-Target].MODCODE,
[T-temp-Actual].MODCODE
FROM [T-temp-Actual] INNER JOIN [T-temp-Target] ON
([T-temp-Actual].TRAINEEID = [T-temp-Target].TRAINEEID) AND
([T-temp-Actual].MODCODE = [T-temp-Target].MODCODE)
WHERE ((([T-temp-Actual].MODCODE) Is Null));
View 2 Replies
View Related
Aug 7, 2015
I need to find all MaintItems which field MIC don't exist in either MIC1 or MIC2. So the only result which I need to see is MaintItem '5100161086' as MIC <> MIC1 Unfortunately I can create query which would approve '5100662734' as well
MaintItem ------MIC------ MIC1 ------ MIC2
5100634036 50000173 50000173
5100662790 50000174 50000174
5100662734 50000145 50000145 50000180
5100662734 50000180 50000145 50000180
5100161086 500001711 50000173
So bottom line I need a query which will display only the row below as MIC doesn't exist in neither MIC1 nore MIC2. Also I will have to deal with much more MICs soon so maybe there is a way to concatenate them and compare, isn't it? 5100161086 500001711 50000173
Attached query is what I got so far, but that displays last 3 rows of table above
View 3 Replies
View Related