Queries :: Add Columns To Grouped Max (date) Query

Mar 14, 2013

I have a database that tracks students and their test scores. I am trying to figure out a way to where it will pull the student's latest test score and compare it to see if they fall within standards. So far I have 3 tables.

tblStudents
studentID
studentName
studentEmail

tblResults
resultID
resultStudent
resultDate
resultTest
resultScore

tblTests
testID
testName
testPassScore

The query I have written looks like this: SELECT tblStudents.studentID, Max(tblResults.resultDate) FROM tblStudents LEFT JOIN tblResults ON tblStudents.studentID = tblResults.resultStudent GROUP BY tblStudents.studentID." The data pulls just fine at this point. What I'm trying to figure out is how to then add more columns to this query to start doing comparisons. When I try to add more columns it tries to use them for additional grouping and adds many more records.

View Replies


ADVERTISEMENT

Queries :: Totals Query Grouped Across Columns

Mar 5, 2015

I have simple table data structured as follows;[Origin], [Code], [Weight]. The Code field is a lookup field that will contain one of 8 choices; 10, 13, 13c, 23, 25, 27, 27a, & other. The other fields are pretty much self explanatory. Sample data would look like this:

Code:
Origin Code Weight
Edison 13 4.25
Edison 13c 2.87
Piscataway 10 5.45
Middlesex 23 1.24
Edison 13 5.21

What I need to create is a totals query where I first group by origin value, then a column for each "code" value which totals the weight for that "code". A sample output would look something like this:

Code:
Origin 10 13 13c 23 25 27 27a other
Edison 9.46 2.87
Piscataway 5.45
Middlesex 1.24

The only way I can think to accomplish this is to restructure the original table to include a field for each code and enter the weight in the appropriate 'code' field. If this is the only solution then Ill have to live with it, but is there any way to create this output using my original structure?

View 1 Replies View Related

Queries :: Concatenate Multiple Records Grouped By Date?

May 2, 2014

I have a rates table with 3 fields : [RateDate], [CurrencyID], [FXRate]

I also have a currencies table with 2 fields : [CurrencyID], [CurrencyCode]

Where [CurrencyCode] is just the 3-character currency code (i.e. EUR, GBP, USD etc.)

The rates table uses a composite primary key across [RateDate] and [CurrencyID] - i.e., there should only be one unique record for each combination of date and currency.

Not every date will be present in the table and, within each of those dates, not every currency will be present (but at least one, obviously)

I want to write a query which will return two fields. The first field will contain all of the unique dates in the table for which the [FXRate] field (for any currency) is blank / null. Straightforward enough :

Code:
SELECT [tblRates].[RateDate]
FROM [tblRates]
INNER JOIN [tblCurrencies]

[Code]....

But this gives me a separate record for each date / currency combination in the returned dataset. I just want one record per date and all of the currency codes in a single string (separated by some delimiter) as a text field.

View 3 Replies View Related

Queries :: Grouped Query That Returns A List Of All Periods

Nov 21, 2013

I have a grouped query that returns a list of all periods qryPeriod

Code:
SELECT [tblMaster].Year, [tblMaster].Week, ([Year] & " - " & Right(0 & [Week],2)) AS Period
FROM [tblMaster]
GROUP BY [tblMaster].Year, [tblMaster].Week, ([Year] & " - " & Right(0 & [Week],2));

Year | Week | Period
2013 | 48 | 2013 - 48
2013 | 49 | 2013 - 49
2013 | 50 | 2013 - 50
2013 | 51 | 2013 - 51
2013 | 52 | 2013 - 52
2014 | 1 | 2014 - 01
2014 | 2 | 2014 - 02
2014 | 3 | 2014 - 03
2014 | 4 | 2014 - 04

[code]...

these are then used as the start of a between lookup against [tblMaster] along with the last record in the qryPeriod (2014 - 04)...I will need 4 queries so If someone can sort out last period - 8 I can probably do the others.would DLookUp do this say return the last 4 values, Last 6 Values and Last 8 Values

View 6 Replies View Related

Queries :: Query Between Dates But With Count Grouped By Model Number?

Mar 18, 2013

I currently have a query of between dates which the user enters, but when I try to get a total count of model numbers it gives totals for each date. I am trying to get a count of model numbers between these dates with the dates excluded in the grouping.

View 14 Replies View Related

Show Grouped Date In Chart

Jan 18, 2006

Hi!

I use MS Graph and need show 2 data types:
1. Invoice Value, EUR
2. Date
Date axis group records by month, for Example Period from 2005.01.01 And 2006.01.01 has 12 positions in Date Axis.
Her I have problem: I need show sum of Values for every month.
For example in Period from 2005.01.01 till 2005.02.01 I have 3 Values: 200, 500, 600EUR. Her I need to show 1300EUR, and so every month. Her is my strandart code:

Dim strSQL1 As String
strSQL1 = "SELECT Date As Date, Value FROM Table WHERE (Date BETWEEN 2005.01.01 And 2006.01.01)"
Me!chrStatistik.RowSource = strSQL1

Thank You in advace for help.

View 5 Replies View Related

Queries :: Select Last Input From Several Date Columns

Oct 2, 2013

Having built a database that tracks projects across their lives, I've now been asked it I can identify the latest status of the project in a "quick view"

The table "All Projects" has columns that list the Project Number; Project Title; Project Manager and further colunms that list dates that the various stages of the project were achieved. i.e. Start Date; Date Milestone 1 Completed; Date Milestone 2 completed etc.

The projects are such that Milestone 5 may be completed before Milestone 2 and so on, so I need to be able to identify which Milestone was the last to be completed.

I thought of trying an IIF but the progress across the Milestones isn't logical so it won't work. I found something on the Internet about "Greatest" being used on some other program (not Access), which Access didn't like at all!

If the requirement had been given before starting building the db, I would have done everything differently, but I have no real desire to go back to stage 1 and start again, so how or if it's possible to find the highest / latest date relevant to the Project Number across the row of data ?

View 6 Replies View Related

Queries :: Return Max Date Of Multiple Columns

Jul 28, 2014

How do you return the most recent date of multiple columns.

I have a table (tbl_courses) that has a list of training courses. We want to know when a client completed the course most recently.

The problem is, for one course there has been up to 4/5 different variations of the course with different names over the years. E.g. "Drug awareness" has also been known as "Drug Aware" "Illegal Substances" and "Stoppers". I want to pull through the most recent date for all of the above.

We have a field in the Courses table that links the courses into groups (e.g. All drug aware courses come under "23"). Not sure if that works?

Is there a way to do this? The Tbl_Courses is linked to Tbl_Clients via a ClientID.

I've managed to do it in SQL using GREATEST() but that isn't an option in Access.

View 6 Replies View Related

Queries :: Date - Multiple Columns Into Single Column

Jun 6, 2013

I want to create the date from multiple columns to single colums. Just for example

table 1 (local purchase)
Itemname Date
Apple 12/01/2013
Mango 13/01/2013

Table 2 (Import purchase)
Item Name DAte
Apple 12/04/2013
Mango 08/06/2013

Now i want to make one query, which can you the date as follows when we give criteria = apple

Item Name Date purchase mode
Apple 12/01/2013 local
Apple 12/04/2013 Import

Means two dates from different table into one query column... One way in my mind to make one table for both tables.

View 9 Replies View Related

Queries :: Add Comparatives To Grouped Totals Queries

May 23, 2013

I have a totals query of phone call charges by phone number and I want to show a "budget" amount for each number (same amount for all) and a variance against that budget.

How I can do this at the grouped (phone number) level rather than at the individual call level?

Please see current query below:

SELECT Call1CurrentTbl.電話番号(MSN), Sum(Call1CurrentTbl.料金) AS 料金OfSum
FROM Call1CurrentTbl
GROUP BY Call1CurrentTbl.電話番号(MSN), Call1CurrentTbl.[レコード区分], Call1CurrentTbl.表示区分
HAVING (((Call1CurrentTbl.[レコード区分])=2) AND ((Call1CurrentTbl.表示区分)=10));

View 2 Replies View Related

Queries :: Selecting Max From Grouped Data

Nov 26, 2014

I am having trouble writing what I think should be a fairly straight forward query... I am have a table with 2 fields, the first contains a list of subjects, the second contains a list of scores that students got in their tests in that subject.

So the data looks like this:

Maths 54
Maths 69
Maths 41
English 71
English 55
Art 44
Art 43
Art 66

I would like to write a query that selects only the highest score for each subject and presents it like this:

Maths 69
English 71
Art 66

View 4 Replies View Related

Queries :: Count Active Members Grouped By Month

May 5, 2015

I am trying to get active member count by month in MS Access.

Table looks like this:

admin ID firstName sDate eDate 1 Adam 01/01/2015 01/04/2015 2 Ben 01/02/2015 15/04/2015 3 Carl 01/02/2015 13/03/2015 4 Don 13/01/2015

Required output would be like this

2015-Jan: 2
2015-Feb: 4
2015-Mar: 3
2015-Apr: 3
2015-May:1
etc..

I got this far:
SELECT DISTINCT count(a.ID) as mCount, year(dimDate.Date) as [Year], month(dimDate.Date) as [Month]
FROM admin AS a INNER JOIN dimDate ON (dimDate.Date >= a.sDate AND dimDate.Date <= a.eDate) OR (dimDate.Date >= a.sDate AND dimDate.Date = null)
GROUP BY year(dimDate.Date), month(dimDate.Date)
ORDER BY year(dimDate.Date), month(dimDate.Date)

Query4 mCount Year Month 31 2015 1 71 2015 2 44 2015 3 13 2015 4

View 2 Replies View Related

Queries :: Calculate Percentage On Grouped And Filtered Data

Jul 20, 2015

I'm very new to Access and I'm attempting to write an expression in a query that will calculate the % of the count of "Exchange" field (Exchange is a text field and is grouped and the count based on each unique name) where the total count is based on the filter where "Group" = 'FS' or 'S'.

The below seems to work, but there is a better way of going about this (especially if I have to add more filter criteria). I added a pic of the query I'm trying to build.

PercentofTotal: (Count([Exchange])/DCount(Count([Exchange]),"[Holdings]","[Asset Group] = 'FS' OR [Asset Group]='S'"))

View 11 Replies View Related

Queries :: Grouped Sum With Proportion Of Total (Access 2007)

Feb 20, 2015

I have a table of transactions (close to 1m records) from which I want to query totals by currency and direction (ins and outs) and then also show the proportion of the overall total for each currency. All amounts are absolute (i.e. ins and outs both represented by positive numbers)

To throw some added complexity into the mix, the transaction table records only refer to account (AccountID), which links to a separate account and currency tables.

I can query the sum totals by currency and direction (although I'm not totally happy with the SQL syntax .

Code:
SELECT tblCurrencies.CurrencyCode,
tmp1.SumPay,
tmp1.SumPayUSD,
tmp2.SumRec,
tmp2.SumRecUSD

[Code] .....

I'm struggling to get the proportions per currency though? I tried adding :

Code:
((SumPayUSD+SumRecUSD)/Sum(tblTransactions.USDAmount)) AS Proportion

But it tells me that the specified field 'tblTransactions.USDAmount' could refer to more than one table listed in the FROM clause of the SQL statement.

View 3 Replies View Related

Queries :: Find Latest Date In A Table Where Dates Are In 2 Separate Columns And Multiple Rows

May 19, 2015

I am trying to find the latest date in a table where the dates are in 2 separate columns and multiple rows. (there are business reasons why there are 2 dates per row they represent different but comparable activities)

I have a table "Assessment tracker" with the following structure

Name Type
Candidate short text
Unit short text
EV1 Date Date
EV2 Date Date

My Data:

Candidate Unit EV1Date EV2 Date
TH1 10 07/05/2015 25/05/15
TH1 10 07/05/2015 07/06/15

I have a query "Candidate AC Dates" that compares the 2 dates EV1 and EV2 and outputs a 3rd column with the latest date.

Query:
PARAMETERS [Candidate Name] Value;
SELECT [Assessment Tracker].Candidate, [Assessment Tracker].Unit, [Assessment Tracker].[EV1 Date], [Assessment Tracker].[EV2 Date], Max(MaxDate([Assessment Tracker]![EV1 Date],[Assessment Tracker]![EV2 Date])) AS Achdate
FROM UnitData INNER JOIN [Assessment Tracker] ON UnitData.Unit = [Assessment Tracker].Unit

[Code]....

Output:

CandidateUnitEV1 DateEV2 DateAchdate
TH11007/05/2015 25/05/201525/05/2015
TH11007/05/2015 07/06/201507/06/2015

It does this by using a function shamelessly copied from the web somewhere...

Function Maxdate(ParamArray FieldArray() As Variant)
' Declare the two local variables.
Dim I As Integer
Dim currentVal As Date' Set the variable currentVal equal to the array of values.
currentVal = FieldArray(0)
' Cycle through each value from the row to find the largest.

[Code]....

This is working well (I think)

I then want to find the latest date for the 2 records i.e. the Max value for the Achdate.

Query:
SELECT [Candidate AC Dates].Candidate AS Expr1, [Candidate AC Dates].Unit AS Expr2, Max([Candidate AC Dates].Achdate) AS MaxOfAchdate
FROM [Candidate AC Dates]
GROUP BY [Candidate AC Dates].Candidate, [Candidate AC Dates].Unit
ORDER BY [Candidate AC Dates].Candidate, [Candidate AC Dates].Unit, Max([Candidate AC Dates].Achdate) DESC;

But this is returning

Candidate Unit MaxOfAchdate
TH1 1025/05/2015

I expect it to return

Candidate UnitMaxOfAchdate
TH1 10 07/06/2015

It looks to me like MAX is considering only the day value rather than the whole date. I suspect this is because it is considering the results of the function in the first query as a short text rather than a date field. (I've tried to force this through declaring the variables as dates but don't know where else to force this. (I am UK based hence the DD/MM/YYYY format)

View 14 Replies View Related

Queries :: Adding Calculations To Queries Based On Columns In Query

Feb 18, 2014

I am trying to add calculations to queries based on columns in the query... it seems to randomly expect 'Expression' or 'Group by' as column types, and Im having to create 3 sets of queries following on from each other to de-dupe data and allow filters on calculated values.

Also I've got a function which turns a date into a quarterly cohort, e.g. Oct 2013 -> 20134. I use ot on a lot of dates. I created a VBA function, CohortQ used as follows in queries:

Cohort: IIf Year([InputDate]) < 1990 or Year([InputDate]) > 2020, 0 CohortQ([InputDate]))

In the VBA, InputDate is defined as a date

Code:
Function CohortQ(InputDate As Date) As Integer
If InputDate = 0 Then
CohortQ = 0
Exit Function
End If

[Code] .....

But when I run it on a date field, it gives me a data mismatch error. I can't step through as it's working on 600K rows.
If I put the function into the query,

Cohort: IIf Year([InputDate]) < 1990 or Year([InputDate]) > 2020, 0 Year([InputDate])*10+DatePart("q",[InputDate]))

it works.

View 3 Replies View Related

Queries :: Run A Query With Several Columns

Jan 3, 2014

I run a query with several columns. The first column in that query is full of individual names; about 50. I have another spreadsheet with three names. I used to be able to set a criteria or a filter (whatever you want to call it) in a query that when "Run" would only return to me the names from the spreadsheet with 3. Not a drop box or a pop up where I have to fill out the name, just a spreadsheet with all the transactions that occurred with these specific three individuals.

View 1 Replies View Related

Queries :: Query Limits Itself To 16 Columns

Aug 18, 2013

Why is my query limiting itself to only 16 columns? when I tab right for another field, it jumps back to the first field. I have other queries with far more columns than that. My DB size is 3,400 kb.

View 3 Replies View Related

Queries :: Subtract Two Columns Within A Query

Jul 22, 2014

I have two calculated columns in my query for example... table.num1 - table.num2 as "Col1" and table.num1 - table.num3 as "Col2"

I then want another column equal to:
Col1 - Col2
I know that I could say:
(table.num1 - table.num2) - (table.num1 - table.num3)

but I am wondering if there is an easy way to just take two calculated columns of the query to use in the calculation of another column.

doing something like:
Col3: Col1 - Col2
doesnt work because it doesnt see Col1 and Col2 within the tables.

View 7 Replies View Related

Queries :: Columns In Query Don't Match

Jan 1, 2014

I have several tables that I need to join together to create a single form for multiple entries. Job Table, OPR Table, Organization, Program List Table, Program Notes, Rank, Reference Table, and Status Table.

Ultimately, I need to be able to display all of these in one form and allow for adding/editing notes from the Program Notes section. I also need to be able to let the user look up all info by selecting the Program Name and have the other field populate correctly. The issue I am running into is that I cannot get the Program Notes table to join to the Program List table correctly.

This is what I attempted to use in SQL:
SELECT [Program Name], [Status], [Reference], [Self-Inspection], [IG Checklist], [Continuity Book], [Bragging Paper], [Program Strengths], [ORI Reports], [Best Practices]
FROM [Program List Table]
UNION
SELECT [Log Date], [Log Entry]
FROM [Program Notes]

However, I keep getting an error. I have read that it is because I don't have the same amount of columns, but the tables don't have the same information.I have also tried to do it through a normal query and through a third table, however I get errors about ambiguous outer joins and I can't seem to make that work either.

View 8 Replies View Related

Queries :: Query Group By And Display Other Columns

Sep 2, 2013

I have a table with 4 columns :

Product Price Quantity Supplier

Product1 5 240 A
Product1 7 19 B
Product1 6 12 C
Product2 96 0 A
Product2 98 23 B
Product2 99 44 C

There are 3 suppliers for the products (name of the suppliers are A, B and C).I want to make a query with the following result :

Product1 5 240 A
Product2 98 23 B

In other words :Showing a grouped list (grouped by products), with the lowest price of the supplier who has stock (quantity >0).I can make a list of grouped products with the lowest price, but it's not possible for me to show the stock and the supplier that's related with it.

View 2 Replies View Related

Queries :: Expression Or SQL To Count Query Columns?

Jan 7, 2014

I'm looking for an expression or SQL for use in a query that will count the number of columns in another query. I do not need to count the records, I just need to know how many columns. I can't seem to locate a reference to a column count - everything points me to record count.

View 13 Replies View Related

Queries :: Counting Multiple Columns In A Query?

Apr 6, 2015

Student ID
Command over subject
Teaching Subject
Explaining things
Pedagogy Methods
Solicited_Participation_Class
1
Good
Average
Bad
Good
Bad
2
Bad
Average
Good
Bad
Good
3

[code]......

I have a table given above, table name is student. Which has following sample data.

I want to count the no. of students who say Good, Average ,Bad for every indicator Output from query:

Good
Average
Bad
Command over subject
2
3
1
Teaching Subject
1
5
0

[code]......

How this can be achived from query in MS Access 2010

View 4 Replies View Related

Queries :: Ordering Columns Cross Tab Query

Nov 26, 2013

I have a cross tab query. Essentially it groups together posted volumes into week numbers for different offices.

However, when I run the query, the order of the columns is not in a logical number order. I get Week 1 then Week 10 then Week 11 and Week 2 is further down the list and then Week 20 comes after that.

I would like if at all possible the Week Numbers to follow after one another i.e. Week 1 first then up to Week 52 in correct number order.

In my Dates Table I do have a SortID column which I hoped would resolve this issue so I could sort on the SortID column however this fails to work.

Attached is the query...

Code:
PARAMETERS [Forms]![frmSumOfVolByCCAndFormat]![cmbOfficeSearch] Text ( 255 ), Forms![frmSumOfVolByCCAndFormat]![txtStartDate] DateTime, Forms![frmSumOfVolByCCAndFormat]![txtEndDate] DateTime;
TRANSFORM Sum(tblTrafficEast.TrafficVolume) AS SumOfTrafficVolume
SELECT tblOffice.CostCentre, tblOffice.OfficeName, tblTrafficFormat.Format, Sum(tblTrafficEast.TrafficVolume) AS [Total Volume]

[Code] ....

View 3 Replies View Related

Queries :: Formatting Columns In A Query With Totals

Oct 2, 2013

The data within my tables is formatted correctly and when I run a standard query on the data, it comes through the query with the same formatting. However, when I run a query that needs to total the values (whether it's sum or average) the values lose any formatting (and by total I mean the one in design view, not in datasheet view).

I then need to manually format each columns "Format" and "Decimal Places" properties to what I want. I have quite a few queries with quite a few columns, so this is very time consuming. Is there a way to do this faster without VBA? In Excel I can simply highlight multiple columns and format all of them or apply a format painter. I don't see any similar functionality in Access 2010.

View 1 Replies View Related

Queries :: Query Returning Blank Columns

Jun 24, 2013

I've set up a simple query that returns 6 columns of data.This query then shows on a sub-form elsewhere in my DB.The problem is that the query always appears with a horizontal slider. Allowing the user to scroll across to see the other columns in the query...The problem here is that there ARE no other columns of data. They are just empty. I want to restrict the output of this query to ONLY show the 6 columns that i have specified.

I have tried deleting the columns in Query Designer, then save the Query. But every time i re-open it half a dozen or so blank columns are stuck on the end.

View 4 Replies View Related







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