Phil,
You could try
TRANSFORM Nz(Count([id])/First([TotG]),0) AS Expr1
Duane Hookom
Vevey, Switzerland
From: "Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 21:00
Subject: Re: [MS_AccessPros] Query not responding
Duane Hookom
From: "Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 18:25
Subject: Re: [MS_AccessPros] Query not responding
Then created a crosstab query with SQL of:
This assumes RefID is numeric.
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, November 10, 2016 10:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Sent: Thursday, November 10, 2016 10:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Hi Duane
Hopefully a couple of simple tweaks (!)
1. In the crosstab query, when a value comes out as zero, it displays as blank - how can I get them to display as 0.00?
2. When the crosstab query is being displayed, I can select totals(the sigma icon)and the use the totals bar. However, unlike in other queries where if I save the query and that causes the totals bar to appear next time I open that query, on the crosstab query the totals line doesn't re-appear and I have to select totals again. Can this be changed so that once selected (and saved) it comes up every time?
Indeed, where is the setting for this totals bar stored to make it appear each time in standard queries?
cheers
Phil
On Wednesday, 9 November 2016, 13:17, "Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:
Phil,
In order to understand the crosstab, it is best to change it to a standard totals query to view the data. The crosstab only transforms/pivots the data by moving one group by column to the column headings.
There are a couple other "tricks" in the query I provided so feel free to ask.
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, November 9, 2016 6:52 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Sent: Wednesday, November 9, 2016 6:52 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Hi Duane
Excellent - that seems to be doing the required job. I need now to go through it all in detail to make sure I fully understand how it all fits together. If I am unclear about anything I hope it is ok if I get back to you for further explanation.
John - if you want to abandon the other avenue now that will be fine as I don't want to waste your time although it would be nice to know why it isn't giving the correct figures and maybe to get it to the stage where it does.
Many thanks to you both for your time and expertise in helping me with my problem.
Phil
From: "Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 21:00
Subject: Re: [MS_AccessPros] Query not responding
First create a query to get your totg
===== qgrpRefSeaTotg =====
SELECT [Matches for grid - league].refid AS gRefID, [Matches for grid - league].seasonid AS gSeasonID, Count([Matches for grid - league].id) AS Totg
FROM [Matches for grid - league]
WHERE (((Month([date]))<>5))
GROUP BY [Matches for grid - league].refid, [Matches for grid - league].seasonid;
Then add this query to your crosstab;
PARAMETERS [forms]![live games]![referee] Short;
TRANSFORM Count([id])/First([TotG]) AS Expr1
SELECT [Matches for grid - league].seasonid,
Sum(Abs([sendingsoff]>0 And [RangeName]="all")) AS Reds,
qgrpRefSeaTotg.Totg
FROM Ranges, qgrpRefSeaTotg INNER JOIN [Matches for grid - league] ON (qgrpRefSeaTotg.gSeasonID = [Matches for grid - league].seasonid) AND (qgrpRefSeaTotg.gRefID = [Matches for grid - league].refid)
WHERE ((([Matches for grid - league].refid)=[forms]![live games]![referee]) AND
(([Matches for grid - league].totbooks) Between [fromnum] And [toNum]) AND ((Month([date]))<>5))
GROUP BY [Matches for grid - league].seasonid, qgrpRefSeaTotg.Totg
PIVOT Ranges.RangeName;
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, November 8, 2016 1:09 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Sent: Tuesday, November 8, 2016 1:09 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Hi Duane
OK I have set this up but there is still much I don't yet fully understand and if you can help me through it I would appreciate it
I have simplified it a bit in that I have included the criteria for the referee and also to exclude the month of May into the original query as these 2 filters apply throughout.
I need the most of the values that are returned in the grid to be divided by [totg] where [totg] is the total number of games for the season we are currently processing. I have been using Count of id to arrive at this value. Totg needs to be added as a column itself as well as being used as the divisor for the other values
It must be something similar to the way you added a column for reds and maybe if you can show me how to do it it will enable me to move forwards
many thanks
Phil
From: "Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 18:25
Subject: Re: [MS_AccessPros] Query not responding
If you have a chance to try something new (learn something new).... I just created the table Ranges
RangeName | FromNum | ToNum |
---|---|---|
0 | 0 | 0 |
0-10 | 0 | 10 |
0-20 | 0 | 20 |
0-30 | 0 | 30 |
0-40 | 0 | 40 |
0-50 | 0 | 50 |
0-60 | 0 | 60 |
0-70 | 0 | 70 |
30-40 | 30 | 40 |
40-60 | 40 | 60 |
all | 0 | 10000 |
Then created a crosstab query with SQL of:
PARAMETERS [forms]![live games]![referee] Short;
TRANSFORM Count([Matches for grid - league].id) AS CountOfid
SELECT seasonid, Sum(Abs([sendingsoff]>0 And [RangeName]="all")) AS Reds
FROM [Matches for grid - league], Ranges
WHERE refid=[forms]![live games]![referee] AND totbooks Between [fromnum] And [toNum] AND Month([date])<>5
GROUP BY seasonid
PIVOT Ranges.RangeName;
The query is very efficient and allows you to do some calculations in your form or report. If you want to do it in a query, you may need to create a simple totals query that counts all by referee and season. Then combine the two queries and do the math.
Regards,
Duane
From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 17:48
Subject: Re: [MS_AccessPros] Query not responding
On Nov 8, 2016, at 16:45, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, 7 November 2016, 15:53
Subject: Re: [MS_AccessPros] Query not responding
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, November 8, 2016 12:02 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
Sent: Tuesday, November 8, 2016 12:02 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
still returning whole numbers.
I am fairly sure the figures I am getting are the counts themselves but they are not being divided by gtot for some reason?
From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, 8 November 2016, 17:48
Subject: Re: [MS_AccessPros] Query not responding
Phil-
Try wrapping a CDbl around either part of the expression, as in:
SUM(qryZero.Count0) / CDbl(totg) As 0
John Viescas, author
John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications
www.viescas.com Welcome to the home of John Viescas Consulting. If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book ... |
www.viescas.com Welcome to the home of John Viescas Consulting. If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book ... |
www.viescas.com Welcome to the home of John Viescas Consulting. If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book ... |
www.viescas.com Welcome to the home of John Viescas Consulting. If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book ... |
On Nov 8, 2016, at 16:45, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi John
something not quite right in the calculations where I am dividing by totg - they are all coming out as integers whereas they should all come out with values between 0 and 1
typically totg represents the total games in a season for the specified ref and count0 is always a subset of those same games
any ideas?
Phil
From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, 7 November 2016, 15:53
Subject: Re: [MS_AccessPros] Query not responding
Phil-
I would pull out each of the DCounts into separate queries. For example, convert:
DCount("id","matches for grid - league","[totbooks]=0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg]
into:
qryZero:
SELECT MGL.Season, COUNT(id) As Count0
FROM [matches for grid - league] AS MGL
WHERE [totbooks]=0 AND [refid]= [forms]![live games]![referee] and month([date])<>5
GROUP BY Season;
Then incorporate it back into your main query using an INNER JOIN:
SELECT [Matches for grid - league].Season, Count([Matches for grid - league].id) AS totg, Avg([Matches for grid - league].totbooks) AS avbk, SUM(qryZero.Count0) / totg As 0
FROM [Matches for grid - league] INNER JOIN qryZero ON [Matches for grid - league].Season = qryZero.Season
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;
FROM [Matches for grid - league] INNER JOIN qryZero ON [Matches for grid - league].Season = qryZero.Season
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;
I threw the SUM in there to make sure you don't get a bogus error because Count0 isn't in the GROUP BY - it should be a SUM of exactly one row! "Simply" do that for each of your DCOUNTs - building up a complex INNER JOIN.
John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
(Paris, France)
On Nov 7, 2016, at 4:29 PM, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Here goes - good luck!
SELECT [Matches for grid - league].Season, Count([Matches for grid - league].id) AS totg, Avg([Matches for grid - league].totbooks) AS avbk, DCount("id","matches for grid - league","[totbooks]=0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS 0, DCount("id","matches for grid - league","[totbooks]<11 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-10], DCount("id","matches for grid - league","[totbooks]<21 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-20], DCount("id","matches for grid - league","[totbooks]<31 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-30], DCount("id","matches for grid - league","[totbooks]<41 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-40], DCount("id","matches for grid - league","[totbooks]<51 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-50], DCount("id","matches for grid - league","[totbooks]<61 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-60], DCount("id","matches for grid - league","[totbooks]<66 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-65], DCount("id","matches for grid - league","[totbooks]<71 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-70], DCount("id","matches for grid - league","[totbooks] between 30 and 40 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [30-40], DCount("id","matches for grid - league","[totbooks] between 40 and 60 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [40-60], DCount("id","matches for grid - league","[sendingsoff]>0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [reds%]
FROM [Matches for grid - league]
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;
FROM [Matches for grid - league]
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;
before my last change I had it working on the table 'matches' but I need it to analyse a particular type of match (ie league matches) so I changed it to run on a query which selects just the league matches.
there are about 60000 matches and maybe 45000 league matches.
cheers
Phil
On Monday, 7 November 2016, 15:21, "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:
Phil-
If a query is "too big", you should get a "query too complex" error. If it's taking a long time to run, perhaps it could be optimized. What's the SQL of the query?
John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
(Paris, France)
On Nov 7, 2016, at 4:14 PM, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi John
That looks as if it might be where the issue lies - I will look into it and let you know
many thanks for that.
Another one for you whilst I have you if you don't mind.
I have a query which causes the message 'Access is not responding' - it is quite a complex query in that it has about 12 fields which use fairly involved dcounts.
Is it possible that a query simply becomes too 'big' to run?
cheers
Phil
__._,_.___
Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (33) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
.
__,_._,___
Tidak ada komentar:
Posting Komentar