Senin, 07 November 2016

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;

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;
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: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (9)

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